Grid Layout in java
GridLayout class :
-------------------------
The GridLayout class is used for
creating the gird containing the specific number of rows and columns
The constructors of the
GridLayout class are :
1. GridLayout()
It
is the default constructor of the GridLayout class .
2. GridLayout(int rows ,int
cols)
It
is the constructor which is used for creating the grid with the specific number of rows and columns
The
general form is ,
new
GridLayout( int rows ,int cols)
3. GridLayout(int rows,int
cols,int hgap,int vgap)
It
is used to specify the horizontal and vertical gap to be left between the items.
The
Insets class provides the method known as getInsets which is to be overloaded for specifying the space to be
left from the top,bottom,left and right
margins
import java.applet.*;
import java.awt.*;
/*
<applet
code="GridLayout1" height=200 width=200>
</applet>
*/
public class GridLayout1 extends
Applet
{
public
void init()
{
int
i;
setLayout(new
GridLayout(4,5));
for(i=1;i<=20;i++)
{
add(new
Button("Button "+i));
}
}
public
Insets getInsets()
{
return
new Insets(5,5,5,5);
}
Comments
Post a Comment