public class GroupLayout extends Layout
Sequential: | A sequential group positions its child elements sequentially, one after another. |
Parallel: | A parallel group positions its child elements in the same space on top of each other. Parallel groups can also align the child elements along their baseline. |
The following code builds a simple layout consisting of two labels in one column, followed by two textfields in the next column:
Container panel = ...; GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setAutocreateGaps(true); layout.setAutocreateContainerGaps(true); GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup(); hGroup.add(layout.createParallelGroup().add(label1).add(label2)). add(layout.createParallelGroup().add(tf1).add(tf2)); layout.setHorizontalGroup(hGroup); GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup(); vGroup.add(layout.createParallelGroup(GroupLayout.BASELINE).add(label1).add(tf1)). add(layout.createParallelGroup(GroupLayout.BASELINE).add(label2).add(tf2)); layout.setVerticalGroup(vGroup);
This layout consists of the following:
add
methods.
add
methods of Groups
return
themselves. This allows for easy chaining of invocations. For
example, group.add(label1).add(label2);
is equivalent to
group.add(label1);group.add(label2);
.
GroupLayout
.
setAutocreateGaps()
method. Similarly you can use
the setAutocreateContainerGaps()
method to insert gaps
between the components and the container.Modifier and Type | Class and Description |
---|---|
class |
GroupLayout.Group
Group provides for commonality between the two types of operations
supported by
GroupLayout : laying out components one
after another (SequentialGroup ) or layout on top
of each other (ParallelGroup ). |
class |
GroupLayout.ParallelGroup
A
Group that lays out its elements on top of each
other. |
class |
GroupLayout.SequentialGroup
A
Group that lays out its elements sequentially, one
after another. |
Modifier and Type | Field and Description |
---|---|
static int |
BASELINE
Possible alignment type.
|
static int |
CENTER
Possible alignment type.
|
static int |
DEFAULT_SIZE
Possible value for the add methods that takes a Component.
|
static int |
EAST
Compass-direction east (right).
|
static int |
HORIZONTAL
Possible argument when linking sizes of components.
|
static int |
LEADING
Possible alignment type.
|
static int |
NORTH
Compass-direction North (up).
|
static int |
PREFERRED_SIZE
Possible value for the add methods that takes a Component.
|
static int |
SOUTH
Compass-direction south (down).
|
static int |
TRAILING
Possible alignment type.
|
static int |
VERTICAL
Possible argument when linking sizes of components.
|
static int |
WEST
Compass-direction west (left).
|
Constructor and Description |
---|
GroupLayout(Container host)
Creates a GroupLayout for the specified Container.
|
Modifier and Type | Method and Description |
---|---|
GroupLayout.ParallelGroup |
createBaselineGroup(boolean resizable,
boolean anchorBaselineToTop)
Creates and returns a
ParallelGroup that aligns it's
elements along the baseline. |
GroupLayout.ParallelGroup |
createParallelGroup()
Creates and returns a
ParallelGroup with a
LEADING alignment. |
GroupLayout.ParallelGroup |
createParallelGroup(int alignment)
Creates and returns an
ParallelGroup . |
GroupLayout.ParallelGroup |
createParallelGroup(int alignment,
boolean resizable)
Creates and returns an
ParallelGroup . |
GroupLayout.SequentialGroup |
createSequentialGroup()
Creates and returns a
SequentialGroup . |
boolean |
getAutocreateContainerGaps()
Returns whether or not gaps between the container and the
first/last components should automatically be created.
|
boolean |
getAutocreateGaps()
Returns true if gaps between components are automatically be created.
|
boolean |
getHonorsVisibility()
Returns whether component visibility is considered when sizing and
positioning components.
|
GroupLayout.Group |
getHorizontalGroup()
Returns the
Group that is responsible for
layout along the horizontal axis. |
LayoutStyle |
getLayoutStyle()
Returns the LayoutStyle instance to use
|
Dimension |
getPreferredSize(Container parent)
Returns the preferred size for the specified container.
|
GroupLayout.Group |
getVerticalGroup()
Returns the
ParallelGroup that is responsible for
layout along the vertical axis. |
void |
layoutContainer(Container parent)
Lays out the specified container.
|
void |
linkSize(Component[] components)
Forces the set of components to have the same size.
|
void |
linkSize(Component[] components,
int axis)
Forces the set of components to have the same size.
|
void |
removeLayoutComponent(Component component)
Notification that a
Component has been removed from
the parent container. |
void |
replace(Component existingComponent,
Component newComponent)
Removes an existing component replacing it with the specified component.
|
void |
setAutocreateContainerGaps(boolean autocreatePadding)
Sets whether or not gaps between the container and the first/last
components should automatically be created.
|
void |
setAutocreateGaps(boolean autocreatePadding)
Sets whether or not a gap between components
should automatically be created.
|
void |
setHonorsVisibility(boolean honorsVisibility)
Sets whether component visibility is considered when sizing and
positioning components.
|
void |
setHonorsVisibility(Component component,
Boolean honorsVisibility)
Sets whether the component's visibility is considered for
sizing and positioning.
|
void |
setHorizontalGroup(GroupLayout.Group group)
Sets the
Group that is responsible for
layout along the horizontal axis. |
void |
setLayoutStyle(LayoutStyle layoutStyle)
Sets the LayoutStyle this GroupLayout is to use.
|
void |
setVerticalGroup(GroupLayout.Group group)
Sets the
Group that is responsible for
layout along the vertical axis. |
String |
toString()
Returns a textual description of this GroupLayout.
|
addLayoutComponent, cloneConstraint, equals, getChildrenInTraversalOrder, getComponentConstraint, hashCode, isConstraintTracking, isOverlapSupported, obscuresPotential, overridesTabIndices, updateTabIndices
public static final int NORTH
public static final int EAST
public static final int SOUTH
public static final int WEST
public static final int HORIZONTAL
linkSize(Component[], int)
,
Constant Field Valuespublic static final int VERTICAL
linkSize(Component[],int)
,
Constant Field Valuespublic static final int LEADING
createParallelGroup(int)
,
Constant Field Valuespublic static final int TRAILING
createParallelGroup(int)
,
Constant Field Valuespublic static final int CENTER
createParallelGroup(int)
,
Constant Field Valuespublic static final int BASELINE
createParallelGroup(int)
,
Constant Field Valuespublic static final int DEFAULT_SIZE
public static final int PREFERRED_SIZE
public GroupLayout(Container host)
host
- the Container to layoutIllegalArgumentException
- if host is nullpublic void setHonorsVisibility(boolean honorsVisibility)
true
indicates that
non-visible components should not be treated as part of the
layout. A value of false
indicates that components should be
positioned and sized regardless of visibility.
A value of false
is useful when the visibility of components
is dynamically adjusted and you don't want surrounding components and
the sizing to change.
The specified value is used for components that do not have an explicit visibility specified.
The default is true
.
honorsVisibility
- whether component visibility is considered when
sizing and positioning componentssetHonorsVisibility(Component,Boolean)
public boolean getHonorsVisibility()
public void setHonorsVisibility(Component component, Boolean honorsVisibility)
Boolean.TRUE
indicates that if component
is not visible it should
not be treated as part of the layout. A value of false
indicates that component
is positioned and sized
regardless of it's visibility. A value of null
indicates the value specified by the single argument method
setHonorsVisibility
should be used.
If component
is not a child of the Container
this
GroupLayout
is managing, it will be added to the
Container
.
component
- the componenthonorsVisibility
- whether component
's visibility should be
considered for sizing and positioningIllegalArgumentException
- if component
is null
setHonorsVisibility(boolean)
public String toString()
public void setAutocreateGaps(boolean autocreatePadding)
SequentialGroup
a
gap between the two will automatically be created. The default
is false.autocreatePadding
- whether or not to automatically created a gap
between components and the containerpublic boolean getAutocreateGaps()
public void setAutocreateContainerGaps(boolean autocreatePadding)
autocreatePadding
- whether or not to automatically create
gaps between the container and first/last components.public boolean getAutocreateContainerGaps()
public void setHorizontalGroup(GroupLayout.Group group)
Group
that is responsible for
layout along the horizontal axis.group
- Group
responsible for layout along
the horizontal axisIllegalArgumentException
- if group is nullpublic GroupLayout.Group getHorizontalGroup()
Group
that is responsible for
layout along the horizontal axis.ParallelGroup
responsible for layout along
the horizontal axis.public void setVerticalGroup(GroupLayout.Group group)
Group
that is responsible for
layout along the vertical axis.group
- Group
responsible for layout along
the vertical axis.IllegalArgumentException
- if group is null.public GroupLayout.Group getVerticalGroup()
ParallelGroup
that is responsible for
layout along the vertical axis.ParallelGroup
responsible for layout along
the vertical axis.public GroupLayout.SequentialGroup createSequentialGroup()
SequentialGroup
.SequentialGroup
public GroupLayout.ParallelGroup createParallelGroup()
ParallelGroup
with a
LEADING
alignment. This is a cover method for the more
general createParallelGroup(int)
method.createParallelGroup(int)
public GroupLayout.ParallelGroup createParallelGroup(int alignment)
ParallelGroup
. The alignment
specifies how children elements should be positioned when the
the parallel group is given more space than necessary. For example,
if a ParallelGroup with an alignment of TRAILING is given 100 pixels
and a child only needs 50 pixels, the child will be positioned at the
position 50.alignment
- alignment for the elements of the Group, one
of LEADING
, TRAILING
,
CENTER
or BASELINE
.ParallelGroup
IllegalArgumentException
- if alignment is not one of
LEADING
, TRAILING
,
CENTER
or BASELINE
public GroupLayout.ParallelGroup createParallelGroup(int alignment, boolean resizable)
ParallelGroup
. The alignment
specifies how children elements should be positioned when the
the parallel group is given more space than necessary. For example,
if a ParallelGroup with an alignment of TRAILING is given 100 pixels
and a child only needs 50 pixels, the child will be positioned at the
position 50.alignment
- alignment for the elements of the Group, one
of LEADING
, TRAILING
,
CENTER
or BASELINE
.resizable
- whether or not the group is resizable. If the group
is not resizable the min/max size will be the same as the
preferred.ParallelGroup
IllegalArgumentException
- if alignment is not one of
LEADING
, TRAILING
,
CENTER
or BASELINE
public GroupLayout.ParallelGroup createBaselineGroup(boolean resizable, boolean anchorBaselineToTop)
ParallelGroup
that aligns it's
elements along the baseline.resizable
- whether the group is resizableanchorBaselineToTop
- whether the baseline is anchored to
the top or bottom of the groupcreateBaselineGroup(boolean, boolean)
,
GroupLayout.ParallelGroup
public void linkSize(Component[] components)
Linked Components are not be resizable.
components
- Components to force to have same size.IllegalArgumentException
- if components
is
null, or contains null.public void linkSize(Component[] components, int axis)
Linked Components are not be resizable.
components
- Components to force to have same size.axis
- Axis to bind size, one of HORIZONTAL, VERTICAL or
HORIZONTAL | VERTICALIllegalArgumentException
- if components
is
null, or contains null.IllegalArgumentException
- if axis
does not
contain HORIZONTAL
or VERTICAL
public void replace(Component existingComponent, Component newComponent)
existingComponent
- the Component that should be removed and
replaced with newComponentnewComponent
- the Component to put in existingComponents placeIllegalArgumentException
- is either of the Components are null or
if existingComponent is not being managed by this layout managerpublic void setLayoutStyle(LayoutStyle layoutStyle)
layoutStyle
- the LayoutStyle to usepublic LayoutStyle getLayoutStyle()
public void removeLayoutComponent(Component component)
Component
has been removed from
the parent container. You should not invoke this method
directly, instead invoke removeComponent
on the parent
Container
.removeLayoutComponent
in class Layout
component
- the component to be removedContainer.removeComponent(com.codename1.ui.Component)
public Dimension getPreferredSize(Container parent)
getPreferredSize
in class Layout
parent
- the container to return size forIllegalArgumentException
- if parent
is not
the same Container
that this was created withIllegalStateException
- if any of the components added to
this layout are not in both a horizontal and vertical groupComponent.getPreferredSize()
public void layoutContainer(Container parent)
layoutContainer
in class Layout
parent
- the container to be laid outIllegalStateException
- if any of the components added to
this layout are not in both a horizontal and vertical group