All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object
|
+----java.awt.GridLayout
GridLayout
class is a layout manager that
lays out a container's components in a rectangular grid.
The container is divided into equal-sized rectangles, and one component is placed in each rectangle.
For example, the following is an applet that lays out six buttons into three rows and two columns:
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"));
}
}
It produces the following output:
public GridLayout()
public GridLayout(int rows,
int cols)
One, but not both, of rows
and cols
can
be zero, which means that any number of objects can be placed in a
row or in a column.
public GridLayout(int rows,
int cols,
int hgap,
int vgap)
In addition, the horizontal and vertical gaps are set to the specified values. Horizontal gaps are placed at the left and right edges, and between each of the columns. Vertical gaps are placed at the top and bottom edges, and between each of the rows.
One, but not both, of rows
and cols
can
be zero, which means that any number of objects can be placed in a
row or in a column.
rows
or cols
is invalid.
public int getRows()
public void setRows(int rows)
rows
and cols
is set to zero.
public int getColumns()
public void setColumns(int cols)
rows
and cols
is set to zero.
public int getHgap()
public void setHgap(int hgap)
public int getVgap()
public void setVgap(int vgap)
public void addLayoutComponent(String name,
Component comp)
public void removeLayoutComponent(Component comp)
public Dimension preferredLayoutSize(Container parent)
The preferred width of a grid layout is the largest preferred width of any of the widths in the container times the number of columns, plus the horizontal padding times the number of columns plus one, plus the left and right insets of the target container.
The preferred height of a grid layout is the largest preferred height of any of the widths in the container times the number of rows, plus the vertical padding times the number of rows plus one, plus the top and left insets of the target container.
public Dimension minimumLayoutSize(Container parent)
The minimum width of a grid layout is the largest minimum width of any of the widths in the container times the number of columns, plus the horizontal padding times the number of columns plus one, plus the left and right insets of the target container.
The minimum height of a grid layout is the largest minimum height of any of the widths in the container times the number of rows, plus the vertical padding times the number of rows plus one, plus the top and left insets of the target container.
public void layoutContainer(Container parent)
This method reshapes the components in the specified target
container in order to satisfy the constraints of the
GridLayout
object.
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. The container's free space equals the container's size minus any insets and any specified horizontal or vertical gap. All components in a grid layout are given the same size.
public String toString()
All Packages Class Hierarchy This Package Previous Next Index