java.awt
public class GridLayout extends Object implements LayoutManager, Serializable
Constructor and Description |
---|
GridLayout()
Create a new
GridLayout with one row and any number
of columns. |
GridLayout(int rows,
int cols)
Create a new
GridLayout with the specified number
of rows and columns. |
GridLayout(int rows,
int cols,
int hgap,
int vgap)
Create a new GridLayout with the specified number of rows and
columns and the specified gaps.
|
Modifier and Type | Method and Description |
---|---|
void |
addLayoutComponent(String name,
Component comp)
Add a new component to the layout.
|
int |
getColumns()
Return the number of columns in this layout.
|
int |
getHgap()
Return the horizontal gap.
|
int |
getRows()
Return the number of rows in this layout.
|
int |
getVgap()
Return the vertical gap.
|
void |
layoutContainer(Container parent)
Lay out the container's components based on current settings.
|
Dimension |
minimumLayoutSize(Container cont)
Get the minimum layout size of the container.
|
Dimension |
preferredLayoutSize(Container cont)
Get the preferred layout size of the container.
|
void |
removeLayoutComponent(Component comp)
Remove the indicated component from this layout manager.
|
void |
setColumns(int newCols)
Set the number of columns.
|
void |
setHgap(int hgap)
Set the horizontal gap.
|
void |
setRows(int newRows)
Set the number of rows
|
void |
setVgap(int vgap)
Set the vertical gap.
|
String |
toString()
Return String description of this object.
|
public GridLayout()
GridLayout
with one row and any number
of columns. Both gaps are set to 0.public GridLayout(int rows, int cols)
GridLayout
with the specified number
of rows and columns. Both gaps are set to 0. Note that the row
and column settings cannot both be zero. If both the row and
column values are non-zero, the rows value takes precedence.rows
- Number of rowscols
- Number of columnsIllegalArgumentException
- If rows and columns are both
0, or if either are negativepublic GridLayout(int rows, int cols, int hgap, int vgap)
rows
- Number of rowscols
- Number of columnshgap
- The horizontal gapvgap
- The vertical gapIllegalArgumentException
- If rows and columns are both
0, if either are negative, or if either gap is negativepublic void addLayoutComponent(String name, Component comp)
addLayoutComponent
in interface LayoutManager
name
- The name of the component to add.comp
- The component to add.public int getColumns()
public int getHgap()
public int getRows()
public int getVgap()
public void layoutContainer(Container parent)
layoutContainer
in interface LayoutManager
parent
- The container to lay outpublic Dimension minimumLayoutSize(Container cont)
minimumLayoutSize
in interface LayoutManager
cont
- The parent containerLayoutManager.preferredLayoutSize(Container)
public Dimension preferredLayoutSize(Container cont)
preferredLayoutSize
in interface LayoutManager
cont
- The parent containerLayoutManager.minimumLayoutSize(Container)
public void removeLayoutComponent(Component comp)
removeLayoutComponent
in interface LayoutManager
comp
- The component to removepublic void setColumns(int newCols)
newCols
- IllegalArgumentException
- If the number of columns is
negative, or if the number of columns is zero and the number
of rows is already 0.public void setHgap(int hgap)
hgap
- The horizontal gappublic void setRows(int newRows)
newRows
- IllegalArgumentException
- If the number of rows is
negative, or if the number of rows is zero and the number
of columns is already 0.public void setVgap(int vgap)
vgap
- The vertical gappublic String toString()
toString
in class Object
Object.getClass()
,
Object.hashCode()
,
Class.getName()
,
Integer.toHexString(int)