// Panel 1 JPanel panel1 = new JPanel(); panel1.setBounds(38, 34, 133, 92); getContentPane().add(panel1); // Panel 2 JPanel panel2 = new JPanel(); panel2.setBounds(223, 67, 133, 92); getContentPane().add(panel2);
package com.java.myapp; import java.awt.EventQueue; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; 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 Java GUI Tutorial"); getContentPane().setLayout(null); // Panel 1 JPanel panel1 = new JPanel(); panel1.setBounds(38, 34, 133, 92); panel1.add(new JButton("Button 1")); panel1.add(new JButton("Button 2")); panel1.add(new JButton("Button 3")); getContentPane().add(panel1); // Panel 2 JPanel panel2 = new JPanel(); panel2.setBounds(223, 67, 133, 92); panel2.setBorder(BorderFactory.createTitledBorder("Panel 2")); JLabel label1 = new JLabel("Label 1"); panel2.add(label1); panel2.add(new JLabel("Label 2")); getContentPane().add(panel2); } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท