Package com.jgoodies.forms.builder
Class ButtonBarBuilder
- java.lang.Object
-
- com.jgoodies.forms.internal.AbstractBuilder<B>
-
- com.jgoodies.forms.internal.AbstractButtonPanelBuilder<ButtonBarBuilder>
-
- com.jgoodies.forms.builder.ButtonBarBuilder
-
public final class ButtonBarBuilder extends AbstractButtonPanelBuilder<ButtonBarBuilder>
Builds consistent button bars that comply with popular style guides. Utilizes the JGoodiesFormLayoutand honors the platform'sLayoutStyleregarding 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:
ButtonStackBuilder,LayoutStyle
-
-
Field Summary
Fields Modifier and Type Field Description private static ColumnSpec[]COL_SPECSSpecifies the columns of the initial FormLayout used in constructors.private static RowSpec[]ROW_SPECSSpecifies the FormLayout's the single button bar row.-
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 ButtonBarBuilder()Constructs an empty ButtonBarBuilder on a JPanel.ButtonBarBuilder(javax.swing.JPanel panel)Constructs an empty ButtonBarBuilder on the given panel.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ButtonBarBuilderaddButton(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.ButtonBarBuilderaddButton(javax.swing.JComponent button)Adds a button component that has a minimum width specified by theLayoutStyle.getDefaultButtonWidth().ButtonBarBuilderaddButton(javax.swing.JComponent... buttons)Adds one or many sequences of related buttons.ButtonBarBuilderaddFixed(javax.swing.JComponent component)Adds a fixed size component with narrow margin.ButtonBarBuilderaddGlue()Adds a glue that will be given the extra space, if this button bar is larger than its preferred size.ButtonBarBuilderaddGrowing(javax.swing.JComponent component)Adds a component that grows if the container grows.ButtonBarBuilderaddRelatedGap()Adds the standard horizontal gap for related components.ButtonBarBuilderaddStrut(ConstantSize width)Adds a horizontal strut of the specified width.ButtonBarBuilderaddUnrelatedGap()Adds the standard horizontal gap for unrelated components.static ButtonBarBuildercreate()-
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 columns of the initial FormLayout used in constructors.
-
ROW_SPECS
private static final RowSpec[] ROW_SPECS
Specifies the FormLayout's the single button bar row.
-
-
Method Detail
-
create
public static ButtonBarBuilder create()
- Returns:
- an empty ButtonBarBuilder on a JPanel
- Since:
- 1.8
-
addButton
public ButtonBarBuilder 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<ButtonBarBuilder>- Parameters:
button- the component to add- Returns:
- this builder
- Throws:
java.lang.NullPointerException- ifbuttonisnull
-
addButton
public ButtonBarBuilder 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<ButtonBarBuilder>- Parameters:
buttons- the buttons to add- Returns:
- this builder
- See Also:
AbstractButtonPanelBuilder.addButton(JComponent)
-
addButton
public ButtonBarBuilder 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<ButtonBarBuilder>- Parameters:
actions- an array of buttons to add
-
addFixed
public ButtonBarBuilder addFixed(javax.swing.JComponent component)
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
public ButtonBarBuilder addGrowing(javax.swing.JComponent component)
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
public ButtonBarBuilder 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
public ButtonBarBuilder addRelatedGap()
Adds the standard horizontal gap for related components.- Specified by:
addRelatedGapin classAbstractButtonPanelBuilder<ButtonBarBuilder>- Returns:
- this builder
- See Also:
LayoutStyle.getRelatedComponentsPadX()
-
addUnrelatedGap
public ButtonBarBuilder addUnrelatedGap()
Adds the standard horizontal gap for unrelated components.- Specified by:
addUnrelatedGapin classAbstractButtonPanelBuilder<ButtonBarBuilder>- Returns:
- this builder
- See Also:
LayoutStyle.getUnrelatedComponentsPadX()
-
addStrut
public ButtonBarBuilder addStrut(ConstantSize width)
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:
ColumnSpec.createGap(ConstantSize)
-
-