Showing posts with label what is grid layout in java. Show all posts
Showing posts with label what is grid layout in java. Show all posts

Wednesday, 12 June 2019

Grid layout in java - online help

Grid layout in java:

The Grid layout class automatically arranges components in a grid. The grid layout manager organizes the display into a rectangular grid. All components of the grid are created with equal size.

The grid layout class has three constructors. They are:
GridLayout()
GridLayout(int numrows,int numcols)
GridLayout(int numrows,int numcols,int h,int v)

Parameters:

numrows -determines the number of rows
numcols -determines the number of cols
 -specifies the horizontal gap in pixels between component.
v   -specifies the vertical gap in pixels between component.

Sample program grid layout in java:

import java.awt.*;
import java.applet.*;
public class GridLayoutDemo extends Applet
{
Button b1,b2,b3,b4;
GridLayout g=new GridLayout(2,2);
public void init()
{
setLayout(g);
b1= new Button("sehban");
b2= new Button("reem");
b3= new Button("arman");
b4= new Button("amaal");
add(b1);
add(b2);
add(b3);
add(b4);
}
}