Java开发GUI之GridLayout网格布局
GridLayout是简单的网格布局,使用其可以方便的实现多行多列的布局样式。
1 2 3 4 5 6 7 8 9 10 11 12 13
| static void GridLayoutTest(){a Frame frame = new Frame("Grid"); GridLayout layout = new GridLayout(2, 3, 10, 10); Panel pannel = new Panel(layout); pannel.add(new Button("Button1")); pannel.add(new Button("Button2")); pannel.add(new Button("Button3")); pannel.add(new Button("Button4")); pannel.add(new Button("Button5")); frame.add(pannel); frame.pack(); frame.show(); }
|
效果如下:
GridLayout类中常用方法总结如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| public GridLayout();
public GridLayout(int rows, int cols);
public GridLayout(int rows, int cols, int hgap, int vgap);
public int getRows();
public void setRows(int rows);
public int getColumns();
public void setColumns(int cols) ;
public int getHgap();
public void setHgap(int hgap);
public int getVgap();
public void setVgap(int vgap);
|