Class ButtonBarBuilder
java.lang.Object
com.jgoodies.forms.internal.AbstractBuilder<ButtonBarBuilder>
com.jgoodies.forms.internal.AbstractButtonPanelBuilder<ButtonBarBuilder>
com.jgoodies.forms.builder.ButtonBarBuilder
Builds consistent button bars that comply with popular style guides.
Utilizes the JGoodies
FormLayout and honors the platform's
LayoutStyle regarding button sizes, and gaps.Examples:
// 1) Build and return a bar with three related buttons
return ButtonBarBuilder.create()
.addButton(newButton)
.addRelatedGap()
.addButton(editButton)
.addRelatedGap()
.addButton(deleteButton)
.build();
// 2) Short hand for example 1)
return ButtonBarBuilder.create()
.addButton(newButton, editButton, deleteButton)
.build();
// 3) Build and return a bar with two sections
return ButtonBarBuilder.create()
.addButton(newButton, editButton, deleteButton)
.addUnrelatedGap()
.addButton(moveUpButton, moveDownButton)
.build();
// 4) Short hand for example 3)
return ButtonBarBuilder.create()
.addButton(newButton, editButton, deleteButton,
null,
moveUpButton, moveDownButton)
.build();
// 5) Build and return a complex button bar
return ButtonBarBuilder.create()
.addButton(newButton, editButton, deleteButton)
.addUnrelatedGap()
.addButton(moveUpButton, moveDownButton)
.addGlue()
.addGrowing(legendComponent)
.build();
- Since:
- 1.6
- Version:
- $Revision: 1.18 $
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ColumnSpec[]Specifies the columns of the initial FormLayout used in constructors.private static final RowSpec[]Specifies the FormLayout's the single button bar row.Fields inherited from class AbstractButtonPanelBuilder
focusGroupedFields inherited from class AbstractBuilder
currentCellConstraints -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty ButtonBarBuilder on a JPanel.ButtonBarBuilder(JPanel panel) Constructs an empty ButtonBarBuilder on the given panel. -
Method Summary
Modifier and TypeMethodDescriptionConstructs an array of JButtons from the given Action array, and adds them as a sequence of related buttons separated by a default gap.addButton(JComponent button) Adds a button component that has a minimum width specified by theLayoutStyle.getDefaultButtonWidth().addButton(JComponent... buttons) Adds one or many sequences of related buttons.addFixed(JComponent component) Adds a fixed size component with narrow margin.addGlue()Adds a glue that will be given the extra space, if this button bar is larger than its preferred size.addGrowing(JComponent component) Adds a component that grows if the container grows.Adds the standard horizontal gap for related components.addStrut(ConstantSize width) Adds a horizontal strut of the specified width.Adds the standard horizontal gap for unrelated components.static ButtonBarBuildercreate()Methods inherited from class AbstractButtonPanelBuilder
add, appendColumn, appendGlueColumn, appendGlueRow, appendRelatedComponentsGapColumn, appendRelatedComponentsGapRow, appendRow, appendUnrelatedComponentsGapColumn, appendUnrelatedComponentsGapRow, build, createButton, getColumn, getRow, isLeftToRight, nextColumn, nextRow, setBackground, setBorder, setLeftToRight, setOpaqueMethods inherited from class AbstractBuilder
background, border, border, createComponentFactory, getColumnCount, getComponentFactory, getContainer, getLayout, getPanel, getRowCount, opaque, padding, padding, setComponentFactory
-
Field Details
-
COL_SPECS
Specifies the columns of the initial FormLayout used in constructors. -
ROW_SPECS
Specifies the FormLayout's the single button bar row.
-
-
Constructor Details
-
ButtonBarBuilder
public ButtonBarBuilder()Constructs an empty ButtonBarBuilder on a JPanel. -
ButtonBarBuilder
Constructs an empty ButtonBarBuilder on the given panel.- Parameters:
panel- the layout container
-
-
Method Details
-
create
- Returns:
- an empty ButtonBarBuilder on a JPanel
- Since:
- 1.8
-
addButton
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<ButtonBarBuilder>- Parameters:
button- the component to add- Returns:
- this builder
- Throws:
NullPointerException- ifbuttonisnull
-
addButton
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<ButtonBarBuilder>- Parameters:
buttons- the buttons to add- Returns:
- this builder
- See Also:
-
addButton
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<ButtonBarBuilder>- Parameters:
actions- an array of buttons to add
-
addFixed
Adds a fixed size component with narrow margin. Unlike the buttons, this component is laid out without a minimum width. In other words, the width is determined only by the component's preferred width.- Parameters:
component- the component to add- Returns:
- this builder
-
addGrowing
Adds a component that grows if the container grows. The component's initial size (before it grows) is specified by theLayoutStyle.getDefaultButtonWidth().- Parameters:
component- the component to add- Returns:
- this builder
-
addGlue
Adds a glue that will be given the extra space, if this button bar is larger than its preferred size.- Returns:
- this builder
-
addRelatedGap
Adds the standard horizontal gap for related components.- Specified by:
addRelatedGapin classAbstractButtonPanelBuilder<ButtonBarBuilder>- Returns:
- this builder
- See Also:
-
addStrut
Adds a horizontal strut of the specified width. For related and unrelated components useaddRelatedGap()andaddUnrelatedGap()respectively.- Parameters:
width- describes the gap width- Returns:
- this builder
- See Also:
-