Swing —— Box容器組件

普通 Glue Strut Rigid Filler

 

普通


box.add(new JButton("按鈕1"));

box.add(new JButton("按鈕2"));

box.add(new JButton("按鈕3"));

 

Glue

Glue插入在兩組件之間時,它會將兩組件擠到最左與最右(或最上與最下),不可見的glue將會佔滿整個中間的空間。


box.add(new JButton("按鈕1"));

box.add(Box.createHorizontalGlue());

box.add(new JButton("按鈕2"));

box.add(Box.createHorizontalGlue());

box.add(new JButton("按鈕3"));

 

Strut

當不想讓“按鈕3”自動緊靠右邊,可以使用Strut組件來設置所需要的大小。


 

box.add(new JButton("按鈕1"));

box.add(Box.createHorizontalGlue());

box.add(new JButton("按鈕2"));

box.add(Box.createHorizontalGlue());

box.add(new JButton("按鈕3"));

box.add(Box.createHorizontalStrut(10));

 

Glue

Glue插入在兩組件之間時,它會將兩組件擠到最左與最右(或最上與最下),不可見的glue將會佔滿整個中間的空間。


box.add(new JButton("按鈕1"));

box.add(Box.createHorizontalGlue());

box.add(new JButton("按鈕2"));

box.add(Box.createRigidArea(new Dimension(50, 50)));

box.add(new JButton("按鈕3"));

 

Filler

FillerBox的內部類,它的功能跟Rigid類似,都可以指定長寬的大小限制,且Filler可以指定最大、較佳、最小的長寬大小。

構造函數:

Box.Filler(Dimension min, Dimension pref, Dimension max)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章