FormContainer is a WidgetContainer which arranges its children in a grid. The width of each row and
the height of each column may be different, and a single Widget may occupy a rectangular block of cells.
The column widths and row heights are chosen based on the minimum and preferred sizes of the widgets
contained in them. If a FormContainer is made larger than the preferred size required for its children,
the extra space is divided between rows and columns based on their weights. That is, a column with
weight 2.0 will have twice as much extra width added to it as a column with weight 1.0. A row or column
with weight 0.0 will never be made larger than is required to hold its children.
In addition to the event types generated by all Widgets, FormContainers generate the following
event types:
add
public void add(Widget widget,
int col,
int row)
Add a Widget to this container. The Widget will occupy a single cell, and be positioned using the
default LayoutInfo.
widget
- the Widget to addcol
- the column in which to place the Widgetrow
- the row in which to place the Widget
add
public void add(Widget widget,
int col,
int row,
LayoutInfo layout)
Add a Widget to this container. The Widget will occupy a single cell.
widget
- the Widget to addcol
- the column in which to place the Widgetrow
- the row in which to place the Widgetlayout
- the LayoutInfo to use for this Widget. If null, the default LayoutInfo will be used.
add
public void add(Widget widget,
int col,
int row,
int width,
int height)
Add a Widget to this container. The Widget will occupy a rectangular block of cells, and be positioned
using the default LayoutInfo.
widget
- the Widget to addcol
- the first column the Widget will occupyrow
- the first row the Widget will occupywidth
- the number of columns the Widget will occupyheight
- the number of rows the Widget will occupy
add
public void add(Widget widget,
int col,
int row,
int width,
int height,
LayoutInfo layout)
Add a Widget to this container. The Widget will occupy a rectangular block of cells.
widget
- the Widget to addcol
- the first column the Widget will occupyrow
- the first row the Widget will occupywidth
- the number of columns the Widget will occupyheight
- the number of rows the Widget will occupylayout
- the LayoutInfo to use for this Widget. If null, the default LayoutInfo will be used.
getChild
public Widget getChild(int i)
Get the i'th child of this container.
getChildCells
public Rectangle getChildCells(Widget widget)
Get the range of cells occupied by a Widget.
widget
- the Widget for which to get the cells
- a Rectangle specifying the range of rows and columns occupied by the Widget, or null if
the Widget is not a child of this container
getChildCells
public Rectangle getChildCells(int index)
Get the range of cells occupied by a Widget.
index
- the index of the Widget for which to get the cells
- a Rectangle specifying the range of rows and columns occupied by the Widget
getChildLayout
public LayoutInfo getChildLayout(Widget widget)
Get the LayoutInfo for a particular Widget.
widget
- the Widget for which to get the LayoutInfo
- the LayoutInfo being used for that Widget. This may return null, which indicates that the
default LayoutInfo is being used. It will also return null if the specified Widget is not
a child of this container.
getChildLayout
public LayoutInfo getChildLayout(int index)
Get the LayoutInfo for a particular Widget.
index
- the index of the Widget for which to get the LayoutInfo
- the LayoutInfo being used for that Widget. This may return null, which indicates that the
default LayoutInfo is being used.
getChildren
public Collection getChildren()
Get a Collection containing all child Widgets of this container.
- getChildren in interface WidgetContainer
getColumnCount
public int getColumnCount()
Get the number of columns in this FormContainer.
getColumnWeight
public double getColumnWeight(int col)
Get the weight of a particular column.
col
- the index of the column
getComponent
public JPanel getComponent()
Get the java.awt.Component corresponding to this Widget.
- getComponent in interface Widget
getDefaultLayout
public LayoutInfo getDefaultLayout()
Get the default LayoutInfo.
getMinimumSize
public Dimension getMinimumSize()
Get the smallest size at which this Widget can reasonably be drawn. When a WidgetContainer lays out
its contents, it will attempt never to make this Widget smaller than its minimum size.
- getMinimumSize in interface Widget
getPreferredSize
public Dimension getPreferredSize()
Get the preferred size at which this Widget will look best. When a WidgetContainer lays out
its contents, it will attempt to make this Widget as close as possible to its preferred size.
- getPreferredSize in interface Widget
getRowCount
public int getRowCount()
Get the number of rows in this FormContainer.
getRowWeight
public double getRowWeight(int row)
Get the weight of a particular row.
row
- the index of the row
getWidgetIndex
public int getWidgetIndex(Widget widget)
Get the index of a particular Widget.
widget
- the Widget to locate
- the position of the Widget within this container
layoutChildren
public void layoutChildren()
Layout the child Widgets. This may be invoked whenever something has changed (the size of this
WidgetContainer, the preferred size of one of its children, etc.) that causes the layout to no
longer be correct. If a child is itself a WidgetContainer, its layoutChildren() method will be
called in turn.
- layoutChildren in interface WidgetContainer
remove
public void remove(Widget widget)
Remove a child Widget from this container.
- remove in interface WidgetContainer
widget
- the Widget to remove
remove
public void remove(int index)
Remove a child Widget from this container.
index
- the index of the Widget to remove
setChildCells
public void setChildCells(Widget widget,
Rectangle cells)
Set the range of cells occupied by a Widget.
widget
- the Widget for which to get the cellscells
- a Rectangle specifying the range of rows and columns to be occupied by the Widget
setChildCells
public void setChildCells(int index,
Rectangle cells)
Set the range of cells occupied by a Widget.
index
- the index of the Widget for which to set the cellscells
- a Rectangle specifying the range of rows and columns to be occupied by the Widget
setChildLayout
public void setChildLayout(Widget widget,
LayoutInfo layout)
Set the LayoutInfo for a particular Widget.
widget
- the Widget for which to set the LayoutInfolayout
- the new LayoutInfo. If null, the default LayoutInfo will be used
setChildLayout
public void setChildLayout(int index,
LayoutInfo layout)
Set the LayoutInfo for a particular Widget.
index
- the index of the Widget for which to set the LayoutInfolayout
- the new LayoutInfo. If null, the default LayoutInfo will be used
setColumnCount
public void setColumnCount(int columns)
Set the number of columns in this FormContainer. If this increases the number of columns, the new columns
will have weights of 1.0 by default. If this decreases the number of columns, any child Widgets that
extend beyond the last column will be removed.
setColumnWeight
public void setColumnWeight(int col,
double weight)
Set the weight of a particular column.
col
- the index of the columnweight
- the new weight
setDefaultLayout
public void setDefaultLayout(LayoutInfo layout)
Set the default LayoutInfo.
setRowCount
public void setRowCount(int rows)
Set the number of rows in this FormContainer. If this increases the number of rows, the new rows
will have weights of 1.0 by default. If this decreases the number of rows, any child Widgets that
extend beyond the last row will be removed.
setRowWeight
public void setRowWeight(int row,
double weight)
Set the weight of a particular row.
row
- the index of the rowweight
- the new weight