GridLayout place the components into rectangular grid. Space of container is divided into rows and columns and components are place at the particular cell.
It has following constructors
GridLayout()
It creates a layout with one column per component. Only one row is used.
GridLayout(int rows, int cols)
It creates a layout with the given number of rows and columns.
GridLayout(int rows, int cols, int hgap, int vgap)
It creates a layout with the given number of rows and columns, and the given size of horizontal and vertical gaps between each row and column.
import java.awt.*;
import java.applet.*;
/*
<applet code="GridLayoutDemo1" width=400 height=200>
</applet>
*/
public class GridLayoutDemo1 extends Applet
{
public void init()
{
setLayout(new GridLayout(3,2));
add(new Button("ONE"));
add(new Button("TWO"));
add(new Button("THREE"));
add(new Button("FOUR"));
add(new Button("FIVE"));
add(new Button("SIX"));
}
}
import java.applet.*;
/*
<applet code="GridLayoutDemo1" width=400 height=200>
</applet>
*/
public class GridLayoutDemo1 extends Applet
{
public void init()
{
setLayout(new GridLayout(3,2));
add(new Button("ONE"));
add(new Button("TWO"));
add(new Button("THREE"));
add(new Button("FOUR"));
add(new Button("FIVE"));
add(new Button("SIX"));
}
}
Comments