public final class ButtonStackBuilder extends AbstractButtonPanelBuilder<ButtonStackBuilder>
FormLayout
and honors the platform's
LayoutStyle
regarding button sizes, and gaps.This builder sets a hint for narrow margin for the gridded buttons. This can reduce the button stack's width if some buttons have long texts. For example, a stack with 'OK', 'Cancel', 'Configure…' will likely exceed the minimum button width. The narrow margins help getting narrow stacks. Note that some look&feels do not support the narrow margin feature, and conversely, others have only narrow margins. The JGoodies look&feels honor the setting, the Mac Aqua l&f uses narrow margins all the time.
Example:
The following example builds a button stack with Close, Up and
Down, where Up and Down are related, and Close is not related
to the other buttons, which makes a wide gap for the unrelated and
a smaller gap for the related buttons.
private JPanel createCloseUpDownButtonStack( JButton close, JButton up, JButton down) { return ButtonStackBuilder().create() .addGridded(close) .addUnrelatedGap() .addGridded(up) .addRelatedGap() .addGridded(down) .build(); }
ButtonBarBuilder
,
LayoutStyle
focusGrouped
currentCellConstraints
Constructor and Description |
---|
ButtonStackBuilder()
Constructs a ButtonStackBuilder on a default JPanel
using a pre-configured FormLayout as layout manager.
|
ButtonStackBuilder(JPanel panel)
Constructs a ButtonStackBuilder on the given panel
using a pre-configured FormLayout as layout manager.
|
Modifier and Type | Method and Description |
---|---|
ButtonStackBuilder |
addButton(Action... actions)
Constructs an array of JButtons from the given Action array,
and adds them as a sequence of related buttons separated by a default gap.
|
ButtonStackBuilder |
addButton(JComponent... buttons)
Adds one or many sequences of related buttons.
|
ButtonStackBuilder |
addButton(JComponent button)
Adds a button component that has a minimum width
specified by the
LayoutStyle.getDefaultButtonWidth() . |
ButtonStackBuilder |
addFixed(JComponent component)
Adds a fixed size component.
|
ButtonStackBuilder |
addGlue()
Adds a glue that will be given the extra space,
if this box is larger than its preferred size.
|
ButtonStackBuilder |
addRelatedGap()
Adds the standard gap for related components.
|
ButtonStackBuilder |
addStrut(ConstantSize size)
Adds a strut of a specified size.
|
ButtonStackBuilder |
addUnrelatedGap()
Adds the standard gap for unrelated components.
|
static ButtonStackBuilder |
create()
Creates and returns an empty ButtonStackBuilder.
|
add, appendColumn, appendGlueColumn, appendGlueRow, appendRelatedComponentsGapColumn, appendRelatedComponentsGapRow, appendRow, appendUnrelatedComponentsGapColumn, appendUnrelatedComponentsGapRow, build, createButton, getColumn, getRow, isLeftToRight, nextColumn, nextRow, setBackground, setBorder, setLeftToRight, setOpaque
background, border, border, createComponentFactory, getColumnCount, getComponentFactory, getContainer, getLayout, getPanel, getRowCount, opaque, padding, padding, setComponentFactory
public ButtonStackBuilder()
public ButtonStackBuilder(JPanel panel)
panel
- the layout containerpublic static ButtonStackBuilder create()
public ButtonStackBuilder addButton(JComponent button)
LayoutStyle.getDefaultButtonWidth()
.Although a JButton is expected, any JComponent is accepted to allow custom button component types.
addButton
in class AbstractButtonPanelBuilder<ButtonStackBuilder>
button
- the component to addNullPointerException
- if button
is null
public ButtonStackBuilder addButton(JComponent... buttons)
AbstractButtonPanelBuilder
null
. The next sequence is separated by an
unrelated gap.
Each button has the minimum width as specified by
LayoutStyle.getDefaultButtonWidth()
. The gap width between
the buttons is LayoutStyle.getRelatedComponentsPadX()
.Although JButtons are expected, general JComponents are accepted to allow custom button component types.
Examples:
builder.addButtons(newButton, editButton, deleteButton); builder.addButtons(newButton, editButton, deleteButton, null, printButton);
addButton
in class AbstractButtonPanelBuilder<ButtonStackBuilder>
buttons
- the buttons to addAbstractButtonPanelBuilder.addButton(JComponent)
public ButtonStackBuilder addButton(Action... actions)
AbstractButtonPanelBuilder
addButton
in class AbstractButtonPanelBuilder<ButtonStackBuilder>
actions
- an array of buttons to addpublic ButtonStackBuilder addFixed(JComponent component)
component
- the component to addpublic ButtonStackBuilder addGlue()
public ButtonStackBuilder addRelatedGap()
AbstractButtonPanelBuilder
addRelatedGap
in class AbstractButtonPanelBuilder<ButtonStackBuilder>
public ButtonStackBuilder addUnrelatedGap()
AbstractButtonPanelBuilder
addUnrelatedGap
in class AbstractButtonPanelBuilder<ButtonStackBuilder>
public ButtonStackBuilder addStrut(ConstantSize size)
size
- a constant that describes the gapCopyright © 2002-2015 JGoodies Software GmbH. All Rights Reserved.