GroupLayout groupLayout = new GroupLayout(getContentPane());
package com.java.myapp; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.LayoutStyle.ComponentPlacement; 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, 458, 287); setTitle("ThaiCreate.Com GUI Tutorial"); JButton btn1 = new JButton("Button 1"); JButton btn2 = new JButton("Button 2"); JButton btn3 = new JButton("Button 3"); GroupLayout groupLayout = new GroupLayout(getContentPane()); groupLayout.setHorizontalGroup( groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup() .addGap(34) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup() .addComponent(btn1) .addPreferredGap(ComponentPlacement.RELATED, 196, Short.MAX_VALUE) .addComponent(btn3) .addGap(34)) .addGroup(groupLayout.createSequentialGroup() .addComponent(btn2) .addContainerGap(319, Short.MAX_VALUE)))) ); groupLayout.setVerticalGroup( groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup() .addGap(30) .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE) .addComponent(btn1) .addComponent(btn3)) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(btn2) .addContainerGap(162, Short.MAX_VALUE)) ); getContentPane().setLayout(groupLayout); } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท