Class ButtonStackBuilder
java.lang.Object
com.jgoodies.forms.builder.AbstractFormBuilder
com.jgoodies.forms.builder.PanelBuilder
com.jgoodies.forms.builder.ButtonStackBuilder
A non-visual builder that assists you in building consistent button stacks
using the
FormLayout.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) {
ButtonStackBuilder builder = new ButtonStackBuilder();
builder.addGridded(close);
builder.addUnrelatedGap();
builder.addGridded(up);
builder.addRelatedGap();
builder.addGridded(down);
return builder.getPanel();
}
- Version:
- $Revision: 1.11 $
- Author:
- Karsten Lentzsch
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a ButtonStackBuilder on a default JPanel using a preconfigured FormLayout as layout manager.ButtonStackBuilder(FormLayout layout, JPanel panel) Constructs a ButtonStackBuilder on the given panel and layout.ButtonStackBuilder(JPanel panel) Constructs a ButtonStackBuilder on the given panel using a preconfigured FormLayout as layout manager. -
Method Summary
Modifier and TypeMethodDescriptionvoidCreates aJButtonfor the given Action and adds the button to this builder.voidConstructs an array of JButtons from the given Action array, and adds them as a sequence of related buttons separated by a default gap.voidCreatesJButtons for the given Actions and adds the buttons to this builder.voidCreatesJButtons for the given Actions and adds the buttons to this builder.voidCreatesJButtons for the given Actions and adds the buttons to this builder.voidAdds the given button.voidAdds a sequence of related buttons separated by a default gap.voidAdds the given buttons as a sequence of related buttons.voidAdds the given buttons as a sequence of related buttons.voidAdds the given buttons as a sequence of related buttons.voidaddButtons(JButton[] buttons) Adds a sequence of related buttons separated by a default gap.voidaddFixed(JComponent component) Adds a fixed size component.voidaddGlue()Adds a glue that will be given the extra space, if this box is larger than its preferred size.voidaddGridded(JComponent component) Adds a gridded component.voidAdds the standard gap for related components.voidaddStrut(ConstantSize size) Adds a strut of a specified size.voidAdds the standard gap for unrelated components.Methods inherited from class PanelBuilder
add, add, addLabel, addLabel, addLabel, addLabel, addROLabel, addROLabel, addROLabel, addROLabel, addSeparator, addSeparator, addSeparator, addSeparator, addTitle, addTitle, addTitle, getComponentFactory, getLabelForFeatureEnabledDefault, getPanel, isLabelForApplicable, isLabelForFeatureEnabled, setBackground, setBorder, setComponentFactory, setDefaultDialogBorder, setLabelFor, setLabelForFeatureEnabled, setLabelForFeatureEnabledDefault, setOpaqueMethods inherited from class AbstractFormBuilder
add, add, appendColumn, appendColumn, appendGlueColumn, appendGlueRow, appendLabelComponentsGapColumn, appendParagraphGapRow, appendRelatedComponentsGapColumn, appendRelatedComponentsGapRow, appendRow, appendRow, appendUnrelatedComponentsGapColumn, appendUnrelatedComponentsGapRow, cellConstraints, createLeftAdjustedConstraints, getColumn, getColumnCount, getColumnIncrementSign, getContainer, getLayout, getLeadingColumn, getRow, getRowCount, isLeftToRight, nextColumn, nextColumn, nextLine, nextLine, nextRow, nextRow, setAlignment, setBounds, setColumn, setColumnSpan, setExtent, setHAlignment, setLeftToRight, setOrigin, setRow, setRowSpan, setVAlignment
-
Constructor Details
-
ButtonStackBuilder
public ButtonStackBuilder()Constructs a ButtonStackBuilder on a default JPanel using a preconfigured FormLayout as layout manager. -
ButtonStackBuilder
Constructs a ButtonStackBuilder on the given panel using a preconfigured FormLayout as layout manager.- Parameters:
panel- the layout container
-
ButtonStackBuilder
Constructs a ButtonStackBuilder on the given panel and layout. The layout must have at least one column.- Parameters:
layout- the FormLayout used to layoutpanel- the layout container- Since:
- 1.2
-
-
Method Details
-
addButtons
Adds a sequence of related buttons separated by a default gap.- Parameters:
buttons- an array of buttons to add
-
addFixed
Adds a fixed size component.- Parameters:
component- the component to add
-
addGridded
Adds a gridded component.- Parameters:
component- the component to add
-
addGlue
public void addGlue()Adds a glue that will be given the extra space, if this box is larger than its preferred size. -
addRelatedGap
public void addRelatedGap()Adds the standard gap for related components. -
addStrut
Adds a strut of a specified size.- Parameters:
size- a constant that describes the gap
-
addButton
Adds the given button. Equivalent to:addButton(new JButton[]{button});- Parameters:
button- the button to add- Since:
- 1.3.0
-
addButton
-
addButton
Adds the given buttons as a sequence of related buttons. Equivalent to:addButton(new JButton[]{button1, button2, button3});- Parameters:
button1- the first button to addbutton2- the second button to addbutton3- the third button to add- Since:
- 1.3.0
-
addButton
Adds the given buttons as a sequence of related buttons. Equivalent to:addButton(new JButton[]{button1, button2, button3, button4});- Parameters:
button1- the first button to addbutton2- the second button to addbutton3- the third button to addbutton4- the fourth button to add- Since:
- 1.3.0
-
addButton
Adds a sequence of related buttons separated by a default gap.- Parameters:
buttons- the array of buttons to add- Since:
- 1.3.0
-
addButton
Creates aJButtonfor the given Action and adds the button to this builder. Equivalent to:addButton(new Action[]{action});- Parameters:
action- the Action used to create the button to add- Since:
- 1.3.0
-
addButton
CreatesJButtons for the given Actions and adds the buttons to this builder. Equivalent to:addButton(new Action[]{action1, action2});- Parameters:
action1- the Action used to create the first button to addaction2- the Action used to create the second button to add- Since:
- 1.3.0
-
addButton
CreatesJButtons for the given Actions and adds the buttons to this builder. Equivalent to:addButton(new Action[]{action1, action2, action3});- Parameters:
action1- the Action used to create the first button to addaction2- the Action used to create the second button to addaction3- the Action used to create the third button to add- Since:
- 1.3.0
-
addButton
CreatesJButtons for the given Actions and adds the buttons to this builder. Equivalent to:addButton(new Action[]{action1, action2, action3, action4});- Parameters:
action1- the Action used to create the first button to addaction2- the Action used to create the second button to addaction3- the Action used to create the third button to addaction4- the Action used to create the fourth button to add- Since:
- 1.3.0
-
addButton
Constructs an array of JButtons from the given Action array, and adds them as a sequence of related buttons separated by a default gap.- Parameters:
actions- an array of buttons to add
-