Java Seminar - Grid Layout
Java Seminar - Grid Layout
Grid Layout
PRASHANT SOLANKI
Roll No: 03415002713
Serial No: 17
Class: CSE 2
Subject: Java Programming
Subject Code: ETCS-307
Example:
The following is an applet that lays out six buttons into three rows
and two columns:
CODE:
import java.awt.*;
import java.applet.Applet;
public class ButtonGrid extends Applet {
public void init() {
setLayout (new GridLayout (3,2));
add (new Button ("1"));
add (new Button("2"));
add (new Button("3"));
add (new Button("4"));
add (new Button("5"));
add (new Button("6"));
}
}
Component Orientation
Constructors
Grid Layout class have three constructors.
To create a grid layout with a default one column per component, in a single row.
To create a grid layout with the specified number of rows and columns. All components in the layout are of
public GridLayout()
equal size.
rows - the rows, with the value zero meaning any number of rows.
cols - the columns, with the value zero meaning any number of columns.
To create a grid layout with the specified number of rows and columns. All components in the layout are
given equal size. In addition, the horizontal and vertical gaps are set to the specified values.
rows - the rows, with the value zero meaning any number of rows
cols - the columns, with the value zero meaning any number of columns
hgap - the horizontal gap
vgap - the vertical gap
Method Description
The various methods of GridLayout Consists of the following:
setRows: Sets the number of rows in this layout to the specified value.
setColumns: Sets the number of columns in this layout to the specified value.
setHgap: Sets the horizontal gap between components to the specified value.
setVgap: Sets the vertical gap between components to the specified value.
addLayoutComponent: Adds the specified component with the specified name to the layout.
preferredLayoutSize: Determines the preferred size of the container argument using this grid layout.
minimumLayoutSize: Determines the minimum size of the container argument using this grid layout. The
minimum dimensions needed to lay out the subcomponents of the specified container
is returned.
layoutContainer: Lays out the specified container using this layout. The grid layout manager determines the
size of individual components by dividing the free space in the container into equal-sized
portions according to the number of rows and columns in the layout.