Package com.jgoodies.forms.builder
Class ButtonBarBuilder
- java.lang.Object
-
- com.jgoodies.forms.builder.AbstractBuilder
-
- com.jgoodies.forms.builder.AbstractButtonPanelBuilder
-
- com.jgoodies.forms.builder.ButtonBarBuilder
-
public final class ButtonBarBuilder extends AbstractButtonPanelBuilder
Builds consistent button bars that comply with popular style guides. Utilizes the JGoodiesFormLayout
and honors the platform'sLayoutStyle
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:
ButtonStackBuilder
,LayoutStyle
-
-
Field Summary
Fields Modifier and Type Field Description private static ColumnSpec[]
COL_SPECS
Specifies the columns of the initial FormLayout used in constructors.private static RowSpec[]
ROW_SPECS
Specifies the FormLayout's the single button bar row.-
Fields inherited from class com.jgoodies.forms.builder.AbstractButtonPanelBuilder
focusGrouped
-
Fields inherited from class com.jgoodies.forms.builder.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 ButtonBarBuilder
addButton(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.ButtonBarBuilder
addButton(javax.swing.JComponent button)
Adds a button component that has a minimum width specified by theLayoutStyle.getDefaultButtonWidth()
.ButtonBarBuilder
addButton(javax.swing.JComponent... buttons)
Adds one or many sequences of related buttons.ButtonBarBuilder
addFixed(javax.swing.JComponent component)
Adds a fixed size component with narrow margin.ButtonBarBuilder
addGlue()
Adds a glue that will be given the extra space, if this button bar is larger than its preferred size.ButtonBarBuilder
addGrowing(javax.swing.JComponent component)
Adds a component that grows if the container grows.ButtonBarBuilder
addRelatedGap()
Adds the standard horizontal gap for related components.ButtonBarBuilder
addStrut(ConstantSize width)
Adds a horizontal strut of the specified width.ButtonBarBuilder
addUnrelatedGap()
Adds the standard horizontal gap for unrelated components.ButtonBarBuilder
background(java.awt.Color background)
Sets the panel's background color and makes the panel opaque.ButtonBarBuilder
border(javax.swing.border.Border border)
Sets the panel's border.static ButtonBarBuilder
create()
ButtonBarBuilder
opaque(boolean b)
Sets the panel's opaque state.-
Methods inherited from class com.jgoodies.forms.builder.AbstractButtonPanelBuilder
add, appendColumn, appendGlueColumn, appendGlueRow, appendRelatedComponentsGapColumn, appendRelatedComponentsGapRow, appendRow, appendUnrelatedComponentsGapColumn, appendUnrelatedComponentsGapRow, build, createButton, getColumn, getPanel, getRow, isLeftToRight, nextColumn, nextRow, setBackground, setBorder, setLeftToRight, setOpaque
-
Methods inherited from class com.jgoodies.forms.builder.AbstractBuilder
createComponentFactory, getColumnCount, getComponentFactory, getContainer, getLayout, getRowCount, 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:
addButton
in classAbstractButtonPanelBuilder
- Parameters:
button
- the component to add- Returns:
- this builder
- Throws:
java.lang.NullPointerException
- ifbutton
isnull
-
addButton
public ButtonBarBuilder addButton(javax.swing.JComponent... buttons)
Description copied from class:AbstractButtonPanelBuilder
Adds 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:
addButton
in classAbstractButtonPanelBuilder
- 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:AbstractButtonPanelBuilder
Constructs an array of JButtons from the given Action array, and adds them as a sequence of related buttons separated by a default gap.- Overrides:
addButton
in classAbstractButtonPanelBuilder
- 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:
addRelatedGap
in classAbstractButtonPanelBuilder
- Returns:
- this builder
- See Also:
LayoutStyle.getRelatedComponentsPadX()
-
addUnrelatedGap
public ButtonBarBuilder addUnrelatedGap()
Adds the standard horizontal gap for unrelated components.- Specified by:
addUnrelatedGap
in classAbstractButtonPanelBuilder
- 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)
-
background
public ButtonBarBuilder background(java.awt.Color background)
Description copied from class:AbstractButtonPanelBuilder
Sets the panel's background color and makes the panel opaque.- Overrides:
background
in classAbstractButtonPanelBuilder
- Parameters:
background
- the color to set as new background- See Also:
JComponent.setBackground(Color)
-
border
public ButtonBarBuilder border(javax.swing.border.Border border)
Description copied from class:AbstractButtonPanelBuilder
Sets the panel's border.- Overrides:
border
in classAbstractButtonPanelBuilder
- Parameters:
border
- the border to set- See Also:
JComponent.setBorder(Border)
-
opaque
public ButtonBarBuilder opaque(boolean b)
Description copied from class:AbstractButtonPanelBuilder
Sets the panel's opaque state.- Overrides:
opaque
in classAbstractButtonPanelBuilder
- Parameters:
b
- true for opaque, false for non-opaque- See Also:
JComponent.setOpaque(boolean)
-
-