package com.utstar.factory;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
/**
* GridLayout布局管理器是设定行*列的布局,中途可以增加行或列数,按照添加控件的顺序从左至右从上至下来添加
* 可以设定整体行列之间的间隔,不能跨行跨列,适用于控件布局类似棋盘的样式。
* @author HZ20232
*
*/
public class TestGridLayout extends JFrame{
private static final long serialVersionUID = 6819222900970457455L;
private JButton button1;
private JButton button2;
private JButton button3;
private JButton button4;
private JButton button5;
private JButton button6;
public TestGridLayout(){
this.setSize(600,400);
this.setTitle("测试");
init();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void init(){
button1 = new JButton("NORTH");
button2 = new JButton("SOUTH");
button3 = new JButton("EAST");
button4 = new JButton("WEST");
button5 = new JButton("CENTER");
button6 = new JButton("CENTER6");
GridLayout myLayout = new GridLayout(2,3);
myLayout.setHgap(10);
myLayout.setVgap(10);
this.setLayout(myLayout);
this.add(button1);
this.add(button2);
this.add(button3);
this.add(button4);
this.add(button5);
this.add(button6);
}
public static void main(String args[]){
TestGridLayout test = new TestGridLayout();
}
}
温馨提示:答案为网友推荐,仅供参考