learning java AWT BoxLayout布局管理器
import javax.swing.*; import java.awt.*; public class BoxSpaceTest { private Frame f = new Frame("test"); private Box horizontal = Box.createHorizontalBox(); private Box vertical = Box.createVerticalBox(); public void init(){ horizontal.add(new Button("button01")); horizontal.add(Box.createHorizontalGlue()); horizontal.add(new Button("button02")); horizontal.add(Box.createHorizontalStrut(10)); horizontal.add(new Button("button03")); vertical.add(new Button("vbutton01")); vertical.add(Box.createVerticalBox()); vertical.add(new Button("vbutton02")); vertical.add(Box.createVerticalStrut(10)); vertical.add(new Button("vbutton03")); f.add(horizontal, BorderLayout.NORTH); f.add(vertical); f.pack(); f.setVisible(true); } public static void main(String[] args) { new BoxSpaceTest().init(); } }
output: