import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* BoxLayout使用例子
*
* @author brj
*
*/
public class TestBoxLayout extends JFrame {
TestBoxLayout() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = (JPanel) getContentPane();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
JButton btn = new JButton("center");
btn = new JButton("center");
panel.add(btn, BorderLayout.CENTER);
panel.add(Box.createVerticalStrut(20));
btn = new JButton("north");
panel.add(btn, BorderLayout.NORTH);
btn = new JButton("south");
panel.add(btn, BorderLayout.SOUTH);
btn = new JButton("EAST");
panel.add(btn, BorderLayout.EAST);
btn = new JButton("west");
panel.add(btn, BorderLayout.WEST);
panel.add(Box.createVerticalGlue());
pack();
}
/**
* main method for testing the class TestBoxLayout
*
* @param args
*/
public static void main(String[] args) {
JFrame frame = new TestBoxLayout();
frame.setVisible(true);
}
}