佈局元件 - BorderLayout 搭配 GridLayout
本帖最後由 tonyh 於 2016-9-3 17:10 編輯
- import javax.swing.JFrame;
- import javax.swing.JButton;
- import java.awt.BorderLayout;
- import java.awt.GridLayout;
- import javax.swing.JPanel;
- public class Ch116 {
-
- JFrame fm;
- JButton btn1,btn2,btn3,btn4,btn5,btn6;
- JPanel pn1,pn2;
-
- Ch116()
- {
- btn1=new JButton("xxx");
- btn2=new JButton("xxxxxxx");
- btn3=new JButton("xxxxxxxxxxx");
- btn4=new JButton("xxxxxxxxx xxxxxxx");
- btn5=new JButton("xxx");
- btn6=new JButton("x");
- pn1=new JPanel();
- pn1.setLayout(new GridLayout(4,1,5,5));
- pn1.add(btn1);
- pn1.add(btn2);
- pn1.add(btn3);
- pn1.add(btn4);
-
- pn2=new JPanel();
- pn2.setLayout(new GridLayout(2,1));
- pn2.add(btn5);
- pn2.add(btn6);
-
- fm=new JFrame("BorderLayout 搭配 GridLayout");
- fm.setBounds(100, 100, 450, 300);
- fm.setVisible(true);
- fm.setResizable(true);
- fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- fm.setLayout(new BorderLayout());
- fm.add(pn1,BorderLayout.WEST);
- fm.add(pn2,BorderLayout.EAST);
- }
-
- public static void main(String[] args) {
- new Ch116();
- }
- }
複製代碼 |
附件:
您需要登錄才可以下載或查看附件。沒有帳號?註冊