Class ButtonStackBuilder
- java.lang.Object
-
- com.jgoodies.forms.internal.AbstractBuilder<B>
-
- com.jgoodies.forms.internal.AbstractButtonPanelBuilder<ButtonStackBuilder>
-
- com.jgoodies.forms.builder.ButtonStackBuilder
-
public final class ButtonStackBuilder extends AbstractButtonPanelBuilder<ButtonStackBuilder>
Builds consistent button stacks that comply with popular style guides. Utilizes the JGoodiesFormLayoutand honors the platform'sLayoutStyleregarding 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(); }- Version:
- $Revision: 1.15 $
- See Also:
ButtonBarBuilder,LayoutStyle
-
-
Field Summary
Fields Modifier and Type Field Description private static ColumnSpec[]COL_SPECSSpecifies the FormLayout's the single button stack column.private static RowSpec[]ROW_SPECSSpecifies the rows of the initial FormLayout used in constructors.-
Fields inherited from class com.jgoodies.forms.internal.AbstractButtonPanelBuilder
focusGrouped
-
Fields inherited from class com.jgoodies.forms.internal.AbstractBuilder
currentCellConstraints
-
-
Constructor Summary
Constructors Constructor Description ButtonStackBuilder()Constructs a ButtonStackBuilder on a default JPanel using a pre-configured FormLayout as layout manager.ButtonStackBuilder(javax.swing.JPanel panel)Constructs a ButtonStackBuilder on the given panel using a pre-configured FormLayout as layout manager.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ButtonStackBuilderaddButton(javax.swing.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.ButtonStackBuilderaddButton(javax.swing.JComponent button)Adds a button component that has a minimum width specified by theLayoutStyle.getDefaultButtonWidth().ButtonStackBuilderaddButton(javax.swing.JComponent... buttons)Adds one or many sequences of related buttons.ButtonStackBuilderaddFixed(javax.swing.JComponent component)Adds a fixed size component.ButtonStackBuilderaddGlue()Adds a glue that will be given the extra space, if this box is larger than its preferred size.ButtonStackBuilderaddRelatedGap()Adds the standard gap for related components.ButtonStackBuilderaddStrut(ConstantSize size)Adds a strut of a specified size.ButtonStackBuilderaddUnrelatedGap()Adds the standard gap for unrelated components.static ButtonStackBuildercreate()Creates and returns an empty ButtonStackBuilder.-
Methods inherited from class com.jgoodies.forms.internal.AbstractButtonPanelBuilder
add, appendColumn, appendGlueColumn, appendGlueRow, appendRelatedComponentsGapColumn, appendRelatedComponentsGapRow, appendRow, appendUnrelatedComponentsGapColumn, appendUnrelatedComponentsGapRow, build, createButton, getColumn, getRow, isLeftToRight, nextColumn, nextRow, setBackground, setBorder, setLeftToRight, setOpaque
-
Methods inherited from class com.jgoodies.forms.internal.AbstractBuilder
background, border, border, createComponentFactory, getColumnCount, getComponentFactory, getContainer, getLayout, getPanel, getRowCount, opaque, padding, padding, setComponentFactory
-
-
-
-
Field Detail
-
COL_SPECS
private static final ColumnSpec[] COL_SPECS
Specifies the FormLayout's the single button stack column.
-
ROW_SPECS
private static final RowSpec[] ROW_SPECS
Specifies the rows of the initial FormLayout used in constructors.
-
-
Constructor Detail
-
ButtonStackBuilder
public ButtonStackBuilder()
Constructs a ButtonStackBuilder on a default JPanel using a pre-configured FormLayout as layout manager.
-
ButtonStackBuilder
public ButtonStackBuilder(javax.swing.JPanel panel)
Constructs a ButtonStackBuilder on the given panel using a pre-configured FormLayout as layout manager.- Parameters:
panel- the layout container
-
-
Method Detail
-
create
public static ButtonStackBuilder create()
Creates and returns an empty ButtonStackBuilder.- Returns:
- the created builder
- Since:
- 1.8
-
addButton
public ButtonStackBuilder addButton(javax.swing.JComponent button)
Adds a button component that has a minimum width specified by theLayoutStyle.getDefaultButtonWidth().Although a JButton is expected, any JComponent is accepted to allow custom button component types.
- Specified by:
addButtonin classAbstractButtonPanelBuilder<ButtonStackBuilder>- Parameters:
button- the component to add- Returns:
- this builder
- Throws:
java.lang.NullPointerException- ifbuttonisnull
-
addButton
public ButtonStackBuilder addButton(javax.swing.JComponent... buttons)
Description copied from class:AbstractButtonPanelBuilderAdds one or many sequences of related buttons. A new sequence starts when a button isnull. The next sequence is separated by an unrelated gap. Each button has the minimum width as specified byLayoutStyle.getDefaultButtonWidth(). The gap width between the buttons isLayoutStyle.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);
- Overrides:
addButtonin classAbstractButtonPanelBuilder<ButtonStackBuilder>- Parameters:
buttons- the buttons to add- Returns:
- this builder
- See Also:
AbstractButtonPanelBuilder.addButton(JComponent)
-
addButton
public ButtonStackBuilder addButton(javax.swing.Action... actions)
Description copied from class:AbstractButtonPanelBuilderConstructs an array of JButtons from the given Action array, and adds them as a sequence of related buttons separated by a default gap.- Overrides:
addButtonin classAbstractButtonPanelBuilder<ButtonStackBuilder>- Parameters:
actions- an array of buttons to add
-
addFixed
public ButtonStackBuilder addFixed(javax.swing.JComponent component)
Adds a fixed size component.- Parameters:
component- the component to add
-
addGlue
public ButtonStackBuilder addGlue()
Adds a glue that will be given the extra space, if this box is larger than its preferred size.
-
addRelatedGap
public ButtonStackBuilder addRelatedGap()
Description copied from class:AbstractButtonPanelBuilderAdds the standard gap for related components.- Specified by:
addRelatedGapin classAbstractButtonPanelBuilder<ButtonStackBuilder>
-
addUnrelatedGap
public ButtonStackBuilder addUnrelatedGap()
Description copied from class:AbstractButtonPanelBuilderAdds the standard gap for unrelated components.- Specified by:
addUnrelatedGapin classAbstractButtonPanelBuilder<ButtonStackBuilder>
-
addStrut
public ButtonStackBuilder addStrut(ConstantSize size)
Adds a strut of a specified size.- Parameters:
size- a constant that describes the gap
-
-