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 Grid Bag Layout (GridBagLayout) - Example

Java Grid Bag Layout (GridBagLayout) - Example สำหรับ GridBagLayout เป็นการจัดวาง Layout แบบ Grid (Table) คือจะมีช่องต่าง ๆ เป็นตารางไว้สำหรับการจัดส่ง Layout สำหรับ GridBagLayout กับ GridLayout จะมีลักษณะคล้าย ๆ กันเพียงแต่ GridBagLayout สามารถจัดวาง Controls ต่าง ๆ ทีมีความสูงและกว้างไม่เท่ากันได้ และแต่ล่ะ Cell จะถูกปรับขนาดให้เท่ากับ Controls นั้น ๆ

Java Grid Bag Layout (GridBagLayout)

Java Grid Bag Layout (GridBagLayout) - Example


Syntax
GridBagLayout gridBagLayout = new GridBagLayout();

Component Control ของ Layout

Java Grid Bag Layout (GridBagLayout)

Component GUI บน IDE

Java Grid Bag Layout (GridBagLayout)

ในกรณีที่ทำผ่าน Tools GUI จะมีช่องต่าง ๆ ให้เรากำหนดเพื่อสร้าง Controls

Java Grid Bag Layout (GridBagLayout)

ตัวอย่างแสดงผลบน GUI Toos

Example

MyForm.java
package com.java.myapp;

import java.awt.EventQueue;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;


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, 457, 173);
		setTitle("ThaiCreate.Com GUI Tutorial");
		
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
		getContentPane().setLayout(gridBagLayout);
		
		JButton btn1 = new JButton("Button 1");
		GridBagConstraints gbc_btn1 = new GridBagConstraints();
		gbc_btn1.insets = new Insets(0, 0, 5, 5);
		gbc_btn1.gridx = 0;
		gbc_btn1.gridy = 0;
		getContentPane().add(btn1, gbc_btn1);
		
		JButton btn2 = new JButton("Button 2");
		GridBagConstraints gbc_btn2 = new GridBagConstraints();
		gbc_btn2.insets = new Insets(0, 0, 5, 5);
		gbc_btn2.gridx = 1;
		gbc_btn2.gridy = 1;
		getContentPane().add(btn2, gbc_btn2);
		
		JButton btn3 = new JButton("Button 3");
		GridBagConstraints gbc_btn3 = new GridBagConstraints();
		gbc_btn3.insets = new Insets(0, 0, 5, 0);
		gbc_btn3.gridx = 3;
		gbc_btn3.gridy = 1;
		getContentPane().add(btn3, gbc_btn3);
		
		JButton btn4 = new JButton("Button 4");
		GridBagConstraints gbc_btn4 = new GridBagConstraints();
		gbc_btn4.insets = new Insets(0, 0, 0, 5);
		gbc_btn4.gridx = 2;
		gbc_btn4.gridy = 2;
		getContentPane().add(btn4, gbc_btn4);

	}
	
}

Output

Java Grid Bag Layout (GridBagLayout)

ตัวอย่าง Layout ของ GridBagLayout






   
Share

Property & Method (Others Related)

Java GUI Layout
Java Absolute Layout (AbsoluteLayout) - Example
Java Boder Layout (BorderLayout) - Example
Java Box Layout (BoxLayout) - Example
Java Card Layout (CardLayout) - Example
Java Flow Layout (FlowLayout) - Example
Java Grid Layout (GridLayout) - 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:16:19 / 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 อัตราราคา คลิกที่นี่