- Enclosing class:
- GroupLayout
Group
that aligns and sizes its children.
ParallelGroup
aligns its children in
four possible ways: along the baseline, centered, anchored to the
leading edge, or anchored to the trailing edge.
Baseline
AParallelGroup
that aligns its children along the
baseline must first decide where the baseline is
anchored. The baseline can either be anchored to the top, or
anchored to the bottom of the group. That is, the distance between the
baseline and the beginning of the group can be a constant
distance, or the distance between the end of the group and the
baseline can be a constant distance. The possible choices
correspond to the BaselineResizeBehavior
constants
CONSTANT_ASCENT
and
CONSTANT_DESCENT
.
The baseline anchor may be explicitly specified by the
createBaselineGroup
method, or determined based on the elements.
If not explicitly specified, the baseline will be anchored to
the bottom if all the elements with a baseline, and that are
aligned to the baseline, have a baseline resize behavior of
CONSTANT_DESCENT
; otherwise the baseline is anchored to the top
of the group.
Elements aligned to the baseline are resizable if they have
a baseline resize behavior of CONSTANT_ASCENT
or
CONSTANT_DESCENT
. Elements with a baseline resize
behavior of OTHER
or CENTER_OFFSET
are not resizable.
The baseline is calculated based on the preferred height of each
of the elements that have a baseline. The baseline is
calculated using the following algorithm:
max(maxNonBaselineHeight, maxAscent + maxDescent)
, where the
maxNonBaselineHeight
is the maximum height of all elements
that do not have a baseline, or are not aligned along the baseline.
maxAscent
is the maximum ascent (baseline) of all elements that
have a baseline and are aligned along the baseline.
maxDescent
is the maximum descent (preferred height - baseline)
of all elements that have a baseline and are aligned along the baseline.
A ParallelGroup
that aligns its elements along the baseline
is only useful along the vertical axis. If you create a
baseline group and use it along the horizontal axis an
IllegalStateException
is thrown when you ask
GroupLayout
for the minimum, preferred or maximum size or
attempt to layout the components.
Elements that are not aligned to the baseline and smaller than the size
of the ParallelGroup
are positioned in one of three
ways: centered, anchored to the leading edge, or anchored to the
trailing edge.
Non-baseline ParallelGroup
ParallelGroup
s created with an alignment other than
BASELINE
align elements that are smaller than the size
of the group in one of three ways: centered, anchored to the
leading edge, or anchored to the trailing edge.
The leading edge is based on the axis and
ComponentOrientation
. For the vertical axis the top edge is
always the leading edge, and the bottom edge is always the
trailing edge. When the ComponentOrientation
is
LEFT_TO_RIGHT
, the leading edge is the left edge and the
trailing edge the right edge. A ComponentOrientation
of
RIGHT_TO_LEFT
flips the left and right edges. Child
elements are aligned based on the specified alignment the
element was added with. If you do not specify an alignment, the
alignment specified for the ParallelGroup
is used.
To align elements along the baseline you createBaselineGroup
,
or createParallelGroup
with an alignment of BASELINE
.
If the group was not created with a baseline alignment, and you attempt
to add an element specifying a baseline alignment, an
IllegalArgumentException
is thrown.
- Since:
- 1.6
- See Also:
GroupLayout.createParallelGroup()
,GroupLayout.createBaselineGroup(boolean,boolean)
-
Method Summary
Modifier and TypeMethodDescriptionaddComponent(Component component)
Adds aComponent
to thisGroup
.addComponent(Component component, int min, int pref, int max)
Adds aComponent
to thisGroup
with the specified size.addComponent(Component component, GroupLayout.Alignment alignment)
Adds aComponent
to thisParallelGroup
with the specified alignment.addComponent(Component component, GroupLayout.Alignment alignment, int min, int pref, int max)
Adds aComponent
to thisParallelGroup
with the specified alignment and size.addGap(int pref)
Adds a rigid gap to thisGroup
.addGap(int min, int pref, int max)
Adds a gap to thisGroup
with the specified size.addGroup(GroupLayout.Alignment alignment, GroupLayout.Group group)
Adds aGroup
to thisParallelGroup
with the specified alignment.addGroup(GroupLayout.Group group)
Adds aGroup
to thisGroup
.
-
Method Details
-
addGroup
Adds aGroup
to thisGroup
.- Overrides:
addGroup
in classGroupLayout.Group
- Parameters:
group
- theGroup
to add- Returns:
- this
Group
-
addComponent
Adds aComponent
to thisGroup
.- Overrides:
addComponent
in classGroupLayout.Group
- Parameters:
component
- theComponent
to add- Returns:
- this
Group
-
addComponent
Adds aComponent
to thisGroup
with the specified size.- Overrides:
addComponent
in classGroupLayout.Group
- Parameters:
component
- theComponent
to addmin
- the minimum size or one ofDEFAULT_SIZE
orPREFERRED_SIZE
pref
- the preferred size or one ofDEFAULT_SIZE
orPREFERRED_SIZE
max
- the maximum size or one ofDEFAULT_SIZE
orPREFERRED_SIZE
- Returns:
- this
Group
-
addGap
Adds a rigid gap to thisGroup
.- Overrides:
addGap
in classGroupLayout.Group
- Parameters:
pref
- the size of the gap- Returns:
- this
Group
-
addGap
Adds a gap to thisGroup
with the specified size.- Overrides:
addGap
in classGroupLayout.Group
- Parameters:
min
- the minimum size of the gappref
- the preferred size of the gapmax
- the maximum size of the gap- Returns:
- this
Group
-
addGroup
public GroupLayout.ParallelGroup addGroup(GroupLayout.Alignment alignment, GroupLayout.Group group)Adds aGroup
to thisParallelGroup
with the specified alignment. If the child is smaller than theGroup
it is aligned based on the specified alignment.- Parameters:
alignment
- the alignmentgroup
- theGroup
to add- Returns:
- this
ParallelGroup
- Throws:
IllegalArgumentException
- ifalignment
isnull
-
addComponent
public GroupLayout.ParallelGroup addComponent(Component component, GroupLayout.Alignment alignment)Adds aComponent
to thisParallelGroup
with the specified alignment.- Parameters:
alignment
- the alignmentcomponent
- theComponent
to add- Returns:
- this
Group
- Throws:
IllegalArgumentException
- ifalignment
isnull
-
addComponent
public GroupLayout.ParallelGroup addComponent(Component component, GroupLayout.Alignment alignment, int min, int pref, int max)Adds aComponent
to thisParallelGroup
with the specified alignment and size.- Parameters:
alignment
- the alignmentcomponent
- theComponent
to addmin
- the minimum sizepref
- the preferred sizemax
- the maximum size- Returns:
- this
Group
- Throws:
IllegalArgumentException
- ifalignment
isnull
-