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:

learning java AWT BoxLayout布局管理器

上一篇:BZOJ 1632 [Usaco2007 Feb]Lilypad Pond:spfa【同时更新:经过边的数量最小】【路径数量】


下一篇:【算法题】获取单向链表中倒数第 N 个节点