Packages  This Package  Prev  Next  Index  
	§1.23 Class GridLayout
public  class  java.awt.GridLayout
    extends  java.lang.Object  (I-§1.12)
    implements java.awt.LayoutManager  (II-§1.43)
{
        // Constructors
    public GridLayout(int  rows, int  cols);	§1.23.1
    public GridLayout(int  rows, int  cols,	§1.23.2
                       int  hgap, int  vgap);
        // Methods
    public void addLayoutComponent(String  name,	§1.23.3
                              Component  comp);
    public void layoutContainer(Container  target);	§1.23.4
    public Dimension minimumLayoutSize(Container  target);	§1.23.5
    public Dimension preferredLayoutSize(Container  target);	§1.23.6
    public void removeLayoutComponent(Component  comp);	§1.23.7
    public String toString();	§1.23.8
}
This grid layout manager causes the container's components to be laid out in a rectangular 
grid. The container is split into equal-sized rectangles: one component is placed into each 
rectangle.
For example, the following code says to lay out the 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
:
GridLayout
public GridLayout(int  rows, int  cols)
- Creates a grid layout with the specified number of rows and columns. All 
components in the layout are given equal size.
- One, but not both of rows and columns can be zero, which means that any 
number of objects can be placed in a row or in a column
- Parameters:
 rows
- the rows; zero means "any number"
cols
- the columns; zero means "any number"
  
GridLayout
public GridLayout(int  rows, int  cols, int  hgap, int  vgap)
- Creates 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. 
The horizontal gaps are placed at the left and right edge, and between each 
of the columns. The vertical gaps are placed at the top and bottom edge, 
and between each of the rows. 
- One, but not both of rows and columns can be zero, which means that any 
number of objects can be placed in a row or in a column
- Parameters:
 rows
- the rows; zero means "any number"
cols
- the columns; zero means "any number"
hgap
- the horizontal gap 
vgap
- the vertical gap 
   
addLayoutComponent
public void addLayoutComponent(String  name, Component  comp)
- This method is not used by the grid layout manager.
- Parameters:
 name
- a tag 
comp
- the component to be added
 
layoutContainer
public void layoutContainer(Container  target)
- Lays out the container argument using this layout.
- 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
- Most applications do not call this method directly. This method is called 
when a container calls its layout method (II-§1.11.11).
- Parameters:
 target
- the container in which to do the layout
- See Also:
 - Container  (II-§1.11).
 
    
minimumLayoutSize
public Dimension minimumLayoutSize(Container  target)
- Determines the minimum size of the container argument using this grid 
layout.
- 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 1, 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 1, plus the top and left insets of the 
target container.
- Most applications do not call this method directly. This method is called 
when a container calls its layout method (II-§1.11.11).
- Parameters:
 target
- the container in which to do the layout
- Returns:
 - the minimum dimensions needed to lay out the subcomponents of the 
specified container.
 - See Also:
 - preferredLayoutSize  (II-§1.23.6).
 
    
preferredLayoutSize
public Dimension preferredLayoutSize(Container  target)
- Determines the preferred size of the container argument using this grid 
layout.
- 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 1, 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 1, plus the top and left insets of the 
target container.
- Most applications do not call this method directly. This method is called 
when a container calls its preferredSize method (II-§1.11.17).
- Parameters:
 target
- the container in which to do the layout
- Returns:
 - the preferred dimensions to lay out the subcomponents of the specified container.
 - See Also:
 - minimumLayoutSize  (II-§1.23.5).
 
    
removeLayoutComponent
public void removeLayoutComponent(Component  comp)
- This method is not used by the grid layout manager.
- Parameters:
 comp
- the component to be removed
 
toString
public String toString()
- Returns:
 - a string representation of this grid layout.
 - Overrides:
 - toString in class Object  (I-§1.12.9).
 
Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to doug.kramer@sun.com