標籤:uvc cot nload apt ucf cut eve lbp hex
這裡只介紹了很基礎布局構建及使用,主要是關於 GridBagLayout.
首先整套流程大概是,
聲明一個 GridBagLayout 對象
private GridBagLayout gridBagLayoutFrame = new GridBagLayout();
然後把當前類的容器布局管理器設定為 GridBagLayout
this.setLayout(gridBagLayoutFrame);
最後聲明一個 JPanel 用於添加組件。(當然也可以是別的Panel。如JTabbedPane等)
private JPanel checkBoxTreePanel = new JPanel();
private JTabbedPane tabbedPane = new JTabbedPane();
然後就可以開始使用這個布局管理器來增加和設定組件了。
| |
add(Component comp, Object constraints) |
下面是一個例子:
1 import java.awt.*; 2 import javax.swing.JFrame; 3 import javax.swing.JTabbedPane; 4 import javax.swing.JPanel; 5 6 7 public class WriteForBlog extends JFrame 8 { 9 private GridBagLayout gridBagLayoutFrame = new GridBagLayout();10 private JTabbedPane tabbedPane = new JTabbedPane();11 private JPanel panelOne = new JPanel();12 private JPanel panelTwo = new JPanel();13 14 public WriteForBlog()15 {16 jbInit();17 }18 19 private void jbInit()20 {21 this.setLayout(gridBagLayoutFrame);22 this.setBounds(200, 200, 1000, 600);23 tabbedPane.add(panelOne, "One");24 tabbedPane.add(panelTwo, "Two");25 26 this.add(tabbedPane, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.027 ,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));28 }29 30 public static void main(String[] args)31 {32 WriteForBlog test = new WriteForBlog();33 test.setVisible(true);34 }35 36 }
:
Java GridBagLayout 簡單使用