panel.setLayout(new GridLayout(2,3)); // GridLayout(rows, cols, hgap, vgap)
package com.java.myapp; import java.awt.EventQueue; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import java.awt.GridLayout; 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, 541, 334); setTitle("ThaiCreate.Com GUI Tutorial"); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(2,3)); // GridLayout(rows, cols, hgap, vgap) panel.add(new JButton("Button 1")); panel.add(new JLabel("Label 1")); panel.add(new JButton("Button 2")); panel.add(new JButton("Button 3")); panel.add(new JButton("Button 4")); panel.add(new JLabel("Label 2")); getContentPane().add(panel); } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท