public final class FormLayout extends Object implements LayoutManager2, Serializable
ColumnSpec and RowSpec instances.
CellConstraints. The constraints object specifies where a componen
should be located on the form's grid and how the component should b
positioned. In addition to its constraints object th
FormLayout also considers each component's minimum an
preferred sizes in order to determine a component's size.
ButtonBarBuilder assists you in building butto
bars; it creates a standardized FormLayout and provides a minimal API tha
specializes in adding buttons and Actions. Other builders can creat
frequently used panel design, for example a form that consists of rows o
label-component pairs.
Size interface.
Example 1 (Plain FormLayout):
Example 2 (Using PanelBuilder):PanelBuilder to add components to the form
Example 3 (Using DefaultFormBuilder):
DefaultFormBuildertha ships with the source distribution
ColumnSpec,
RowSpec,
CellConstraints,
AbstractFormBuilder,
ButtonBarBuilder,
DefaultFormBuilder,
FormSpecs,
Size,
Sizes,
Serialized Form| Modifier and Type | Class and Description |
|---|---|
static class |
FormLayout.LayoutInfo
Stores column and row origins.
|
static interface |
FormLayout.Measure
An interface that describes how to measure a
Component. |
| Constructor and Description |
|---|
FormLayout()
Constructs an empty FormLayout.
|
FormLayout(ColumnSpec[] colSpecs)
Constructs a FormLayout using the given column specifications.
|
FormLayout(ColumnSpec[] colSpecs,
RowSpec[] rowSpecs)
Constructs a FormLayout using the given column and row specifications.
|
FormLayout(String encodedColumnSpecs)
Constructs a FormLayout using the given encoded column specifications.
|
FormLayout(String encodedColumnSpecs,
LayoutMap layoutMap)
Constructs a FormLayout using the given encoded column specification
and LayoutMap.
|
FormLayout(String encodedColumnSpecs,
String encodedRowSpecs)
Constructs a FormLayout using the give
encoded column and row specifications and the default LayoutMap.
|
FormLayout(String encodedColumnSpecs,
String encodedRowSpecs,
LayoutMap layoutMap)
Constructs a FormLayout using the give
encoded column and row specifications and the given LayoutMap.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addGroupedColumn(int columnIndex)
Adds the specified column index to the last column group.
|
void |
addGroupedRow(int rowIndex)
Adds the specified row index to the last row group.
|
void |
addLayoutComponent(Component comp,
Object constraints)
Adds the specified component to the layout, using the specifie
constraints object. |
void |
addLayoutComponent(String name,
Component component)
Throws an
UnsupportedOperationException. |
void |
appendColumn(ColumnSpec columnSpec)
Appends the given column specification to the right hand side of al
columns.
|
void |
appendRow(RowSpec rowSpec)
Appends the given row specification to the bottom of all rows.
|
int |
getColumnCount()
Returns the number of columns in this layout.
|
int[][] |
getColumnGroups()
Returns a deep copy of the column groups.
|
ColumnSpec |
getColumnSpec(int columnIndex)
Returns the
ColumnSpec at the specified column index. |
CellConstraints |
getConstraints(Component component)
Looks up and returns the constraints for the specified component.
|
boolean |
getHonorsVisibility()
Returns whether invisible components shall be taken into accoun
by this layout.
|
float |
getLayoutAlignmentX(Container parent)
Returns the alignment along the x axis.
|
float |
getLayoutAlignmentY(Container parent)
Returns the alignment along the y axis.
|
FormLayout.LayoutInfo |
getLayoutInfo(Container parent)
Computes and returns the horizontal and vertical grid origins.
|
int |
getRowCount()
Returns the number of rows in this layout.
|
int[][] |
getRowGroups()
Returns a deep copy of the row groups.
|
RowSpec |
getRowSpec(int rowIndex)
Returns the
RowSpec at the specified row index. |
void |
insertColumn(int columnIndex,
ColumnSpec columnSpec)
Inserts the specified column at the specified position.
|
void |
insertRow(int rowIndex,
RowSpec rowSpec)
Inserts the specified column at the specified position.
|
void |
invalidateLayout(Container target)
Invalidates the layout, indicating that if the layout manage
has cached information it should be discarded.
|
void |
layoutContainer(Container parent)
Lays out the specified container using this form layout.
|
Dimension |
maximumLayoutSize(Container target)
Returns the maximum dimensions for this layout given the component
in the specified target container.
|
Dimension |
minimumLayoutSize(Container parent)
Determines the minimum size of the
parent containe
using this form layout. |
Dimension |
preferredLayoutSize(Container parent)
Determines the preferred size of the parent
|
void |
removeColumn(int columnIndex)
Removes the column with the given column index from the layout.
|
void |
removeLayoutComponent(Component comp)
Removes the specified component from this layout.
|
void |
removeRow(int rowIndex)
Removes the row with the given row index from the layout.
|
void |
setColumnGroup(int... indices)
Sets a single column group, where each column gets the same width.
|
void |
setColumnGroups(int[][] groupOfIndices)
Sets the column groups, where each column in a group gets the sam
group wide width.
|
void |
setColumnSpec(int columnIndex,
ColumnSpec columnSpec)
Sets the ColumnSpec at the specified column index.
|
void |
setConstraints(Component component,
CellConstraints constraints)
Sets the constraints for the specified component in this layout.
|
void |
setHonorsVisibility(boolean b)
Specifies whether invisible components shall be taken into account b
this layout for computing the layout size and setting component bounds.
|
void |
setHonorsVisibility(Component component,
Boolean b)
Specifies whether the given component shall be taken into accoun
for sizing and positioning.
|
void |
setRowGroup(int... indices)
Sets a single row group, where each row gets the same height.
|
void |
setRowGroups(int[][] groupOfIndices)
Sets the row groups, where each row in such a group gets the same grou
wide height.
|
void |
setRowSpec(int rowIndex,
RowSpec rowSpec)
Sets the RowSpec at the specified row index.
|
public FormLayout()
public FormLayout(String encodedColumnSpecs)
DefaultFormBuilder.
Examples:
See the class comment for more examples.
encodedColumnSpecs - comma separated encoded column specificationsNullPointerException - if encodedColumnSpecs is nullLayoutMap.getRoot()public FormLayout(String encodedColumnSpecs, LayoutMap layoutMap)
DefaultFormBuilder.
Examples:
See the class comment for more examples.
encodedColumnSpecs - comma separated encoded column specificationslayoutMap - expands layout column and row variablesNullPointerException - if encodedColumnSpecs o
layoutMap is nullLayoutMap.getRoot()public FormLayout(String encodedColumnSpecs, String encodedRowSpecs)
Examples:
See the class comment for more examples.
encodedColumnSpecs - comma separated encoded column specificationsencodedRowSpecs - comma separated encoded row specificationsNullPointerException - if encodedColumnSpecs or encodedRowSpec
is nullLayoutMap.getRoot()public FormLayout(String encodedColumnSpecs, String encodedRowSpecs, LayoutMap layoutMap)
Examples:
See the class comment for more examples.
encodedColumnSpecs - comma separated encoded column specificationsencodedRowSpecs - comma separated encoded row specificationslayoutMap - expands layout column and row variablesNullPointerException - if encodedColumnSpecs
encodedRowSpecs, or layoutMap is nullpublic FormLayout(ColumnSpec[] colSpecs)
colSpecs - an array of column specifications.NullPointerException - if colSpecs is nullpublic FormLayout(ColumnSpec[] colSpecs, RowSpec[] rowSpecs)
colSpecs - an array of column specifications.rowSpecs - an array of row specifications.NullPointerException - if colSpecs or rowSpecsnullpublic int getColumnCount()
public ColumnSpec getColumnSpec(int columnIndex)
ColumnSpec at the specified column index.columnIndex - the column index of the requested ColumnSpecColumnSpec at the specified columnIndexOutOfBoundsException - if the column index is out of rangepublic void setColumnSpec(int columnIndex,
ColumnSpec columnSpec)
columnIndex - the index of the column to be changedcolumnSpec - the ColumnSpec to be setNullPointerException - if columnSpec is nullIndexOutOfBoundsException - if the column index is out of rangepublic void appendColumn(ColumnSpec columnSpec)
columnSpec - the column specification to be addedNullPointerException - if columnSpec is nullpublic void insertColumn(int columnIndex,
ColumnSpec columnSpec)
columnIndex - index of the column to be insertedcolumnSpec - specification of the column to be insertedIndexOutOfBoundsException - if the column index is out of rangepublic void removeColumn(int columnIndex)
Note: If one of the constraints mentioned abov
is violated, this layout's state becomes illegal and it is unsaf
to work with this layout
A typical layout implementation can ensure that these constraints ar
not violated. However, in some cases you may need to check thes
conditions before you invoke this method. The Forms extras contai
source code for class FormLayoutUtils that provide
the required test methods:
#columnContainsComponents(Container, int) and
#isGroupedColumn(FormLayout, int).
columnIndex - index of the column to removeIndexOutOfBoundsException - if the column index is out of rangeIllegalStateException - if the column contains component
or if the column is already groupedFormLayoutUtils.columnContainsComponent(Container, int),
FormLayoutUtils.isGroupedColumn(FormLayout, int)public int getRowCount()
public RowSpec getRowSpec(int rowIndex)
RowSpec at the specified row index.rowIndex - the row index of the requested RowSpecRowSpec at the specified rowIndexOutOfBoundsException - if the row index is out of rangepublic void setRowSpec(int rowIndex,
RowSpec rowSpec)
rowIndex - the index of the row to be changedrowSpec - the RowSpec to be setNullPointerException - if rowSpec is nullIndexOutOfBoundsException - if the row index is out of rangepublic void appendRow(RowSpec rowSpec)
rowSpec - the row specification to be added to the form layoutNullPointerException - if rowSpec is nullpublic void insertRow(int rowIndex,
RowSpec rowSpec)
rowIndex - index of the row to be insertedrowSpec - specification of the row to be insertedIndexOutOfBoundsException - if the row index is out of rangepublic void removeRow(int rowIndex)
Note: If one of the constraints mentioned abov
is violated, this layout's state becomes illegal and it is unsaf
to work with this layout
A typical layout implementation can ensure that these constraints ar
not violated. However, in some cases you may need to check thes
conditions before you invoke this method. The Forms extras contai
source code for class FormLayoutUtils that provide
the required test methods:
#rowContainsComponents(Container, int) and
#isGroupedRow(FormLayout, int).
rowIndex - index of the row to removeIndexOutOfBoundsException - if the row index is out of rangeIllegalStateException - if the row contains component
or if the row is already groupedFormLayoutUtils.rowContainsComponent(Container, int),
FormLayoutUtils.isGroupedRow(FormLayout, int)public CellConstraints getConstraints(Component component)
component - the component to be queriedNullPointerException - if component is nullIllegalStateException - if component has not bee
added to the containerpublic void setConstraints(Component component, CellConstraints constraints)
component - the component to be modifiedconstraints - the constraints to be appliedNullPointerException - if component or constraintsnullpublic int[][] getColumnGroups()
public void setColumnGroups(int[][] groupOfIndices)
Examples:
groupOfIndices - a two-dimensional array of column groups indicesIndexOutOfBoundsException - if an index is outside the gridIllegalArgumentException - if a column index is used twice
or of a group of indices contains only a single elementpublic void setColumnGroup(int... indices)
Example:
indices - the indices for a single column groupIndexOutOfBoundsException - if an index is outside the gridIllegalArgumentException - if a column index is used twic
or if there is only a single indexNullPointerException - if indices is nullsetColumnGroups(int[][])public void addGroupedColumn(int columnIndex)
columnIndex - the column index to be set groupedpublic int[][] getRowGroups()
public void setRowGroups(int[][] groupOfIndices)
Examples:
groupOfIndices - a two-dimensional array of row group indicesIndexOutOfBoundsException - if an index is outside the gridIllegalArgumentException - if a column index is used twice
or of a group of indices contains only a single elementpublic void setRowGroup(int... indices)
Example:
indices - the indices for a single row groupIndexOutOfBoundsException - if an index is outside the gridIllegalArgumentException - if a row index is used twic
or if there is only a single indexNullPointerException - if indices is nullsetRowGroups(int[][])public void addGroupedRow(int rowIndex)
rowIndex - the index of the row that should be groupedpublic boolean getHonorsVisibility()
setHonorsVisibility(boolean) for details.true if the component visibility is honore
by this FormLayout, false if it is ignored
This setting can be overridden for individual CellConstraint
using setHonorsVisibility(Component, Boolean).public void setHonorsVisibility(boolean b)
true invisible components will be ignored b
the layout. If set to false components will be taken int
account regardless of their visibility. Visible components are alway
used for sizing and positioning.true
It is useful to set the value to false (in other word
to ignore the visibility) if you switch the component visibilit
dynamically and want the container to retain the size an
component positions.
setHonorsVisibility(Component, Boolean).
they are visible, o
false), o
b - true to honor the visibility, i.e. to exclud
invisible components from the sizing and positioning
false to ignore the visibility, in other words t
layout visible and invisible componentspublic void setHonorsVisibility(Component component, Boolean b)
setHonorsVisibility(boolean) for details.component - the component that shall get an individual settingb - Boolean.TRUE to override the containe
default and honor the visibility for the given component
Boolean.FALSE to override the container default an
ignore the visibility for the given component
null to use the container default value as specifie
by getHonorsVisibility().public void addLayoutComponent(String name, Component component)
UnsupportedOperationException. Does not ad
the specified component with the specified name to the layout.addLayoutComponent in interface LayoutManagername - indicates entry's position and anchorcomponent - component to addUnsupportedOperationException - alwayspublic void addLayoutComponent(Component comp, Object constraints)
constraints object. Note that constraints are mutable an
are, therefore, cloned when cached.addLayoutComponent in interface LayoutManager2comp - the component to be addedconstraints - the component's cell constraintsNullPointerException - if constraints is nullIllegalArgumentException - if constraints is neithe
a String, nor a CellConstraints object
or a String that is rejected by the CellConstraints constructionpublic void removeLayoutComponent(Component comp)
removeLayoutComponent in interface LayoutManagercomp - the component to be removed.Container.remove(java.awt.Component),
Container.removeAll()public Dimension minimumLayoutSize(Container parent)
parent containe
using this form layout.
minimumLayoutSize in interface LayoutManagerparent - the container in which to do the layoutparent containerContainer.doLayout()public Dimension preferredLayoutSize(Container parent)
parent
preferredLayoutSize in interface LayoutManagerparent - the container in which to do the layoutparent containerContainer.getPreferredSize()public Dimension maximumLayoutSize(Container target)
maximumLayoutSize in interface LayoutManager2target - the container which needs to be laid outContainer,
minimumLayoutSize(Container),
preferredLayoutSize(Container)public float getLayoutAlignmentX(Container parent)
getLayoutAlignmentX in interface LayoutManager2parent - the parent container0.5f to indicate center alignmentpublic float getLayoutAlignmentY(Container parent)
getLayoutAlignmentY in interface LayoutManager2parent - the parent container0.5f to indicate center alignmentpublic void invalidateLayout(Container target)
invalidateLayout in interface LayoutManager2target - the container that holds the layout to be invalidatedpublic void layoutContainer(Container parent)
FormLayout object.find components that occupy exactly one column or ro
layoutContainer in interface LayoutManagerparent - the container in which to do the layoutContainer,
Container.doLayout()public FormLayout.LayoutInfo getLayoutInfo(Container parent)
#layoutContainerYou must not call this method directly
It may be removed in a future release or the visibilit
may be reduced.parent - the Container to inspectCopyright © 2002-2014 JGoodies Software GmbH. All Rights Reserved.