Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone



Clound SSD Virtual Server

Java Box Layout (BoxLayout) - Example

Java Box Layout (BoxLayout) - Example สำหรับ BoxLayout เป็นการจัดวาง Layout และ Controls แบบ กล่อง คือสามารถเรียงได้ในแนวตั้ง (Y) และ แนวนอน (X) โดย Component Controls ที่ถูกสร้างจะเรียงลำดับกันไป ในรูปแบบของแนวตั้ง หรือ แนวนอนที่กำหนดขึ้น

Java Box Layout (BoxLayout)

Java Box Layout (BoxLayout) - Example


Syntax
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));
//or
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

JButton	btn1 = new JButton("Button 1");
btn1.setAlignmentX(Component.CENTER_ALIGNMENT);
getContentPane().add(btn1);

JButton btn2 = new JButton("Button 2");
btn2.setAlignmentX(Component.CENTER_ALIGNMENT);
getContentPane().add(btn2);

Component Control ของ Layout

Java Box Layout (BoxLayout)

Example

MyForm.java
package com.java.myapp;

import java.awt.Component;
import java.awt.EventQueue;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.BoxLayout;

public class MyForm extends JFrame {

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				MyForm frame = new MyForm();
				frame.setVisible(true);
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MyForm() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		
		getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));
		
		JButton	btn1 = new JButton("Button 1");
		btn1.setAlignmentX(Component.CENTER_ALIGNMENT);
		getContentPane().add(btn1);
		
		JButton btn2 = new JButton("Button 2");
		btn2.setAlignmentX(Component.CENTER_ALIGNMENT);
		getContentPane().add(btn2);
		
		JButton btn3 = new JButton("Button 3");
		btn3.setAlignmentX(Component.CENTER_ALIGNMENT);
		getContentPane().add(btn3);
		
		JButton btn4 = new JButton("Button 4");
		btn4.setAlignmentX(Component.CENTER_ALIGNMENT);
		getContentPane().add(btn4);

	}
	
}

Output

Java Box Layout (BoxLayout)

แบบแรก Y_AXIS (แนวตั้ง)

Java Box Layout (BoxLayout)

ผลลัพธ์ที่ได้

Java Box Layout (BoxLayout)

แบบสอง X_AXIS (แนวนอน)

Java Box Layout (BoxLayout)

ผลลัพธ์ที่ได้






   
Share

Property & Method (Others Related)

Java GUI Layout
Java Absolute Layout (AbsoluteLayout) - Example
Java Boder Layout (BorderLayout) - Example
Java Card Layout (CardLayout) - Example
Java Flow Layout (FlowLayout) - Example
Java Grid Layout (GridLayout) - Example
Java Grid Bag Layout (GridBagLayout) - Example
Java Form Layout (FormLayout) - Example
Java Mid Layout (MidLayout) - Example
Java Spring Layout (SpringLayout) - Example
Java Group Layout (GroupLayout) - Example

ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2013-08-18 13:15:40 / 2013-09-03 13:36:11
  Download : No files
 Sponsored Links / Related

 
Java GUI Layout
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่