import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
/**
* FlowLayout使用例子
* @author brj
*
*/
public class TestFlowLayout extends JFrame {
public TestFlowLayout() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//设置关闭时结束程序
FlowLayout layout = new FlowLayout(FlowLayout.RIGHT, 20, 30);
//右对齐,水平和垂直间隙分别是20,30
setLayout(layout);
JButton btn = new JButton("btn1");
getContentPane().add(btn);
btn = new JButton("btn2");
getContentPane().add(btn);
btn = new JButton("btn3");
getContentPane().add(btn);
pack();
}
public static void main(String[] args) {
JFrame frame = new TestFlowLayout();
frame.setVisible(true);
}
}