import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
/**
* GridLayout使用例子
*
* @author brj
*
*/
public class TestGridLayout extends JFrame {
TestGridLayout() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 关闭选项
GridLayout layout = new GridLayout(2, 2, 10, 10);
// 指定2行,2列;水平和垂直间隙均为10
setLayout(layout);
JButton btn = new JButton("btn1");
getContentPane().add(btn);
btn = new JButton("btn2");
getContentPane().add(btn);
btn = new JButton("btn3");
getContentPane().add(btn);
btn = new JButton("btn4");
getContentPane().add(btn);
pack();
}
public static void main(String[] args) {
JFrame frame = new TestGridLayout();
frame.setVisible(true);
}
}
读完这篇文章后,您心情如何?