com.jgoodies.forms.builder
Class ButtonBarBuilder

java.lang.Object
  extended by com.jgoodies.forms.builder.AbstractFormBuilder
      extended by com.jgoodies.forms.builder.PanelBuilder
          extended by com.jgoodies.forms.builder.ButtonBarBuilder

public final class ButtonBarBuilder
extends PanelBuilder

A non-visual builder that assists you in building consistent button bars that comply with popular UI style guides. It utilizes the FormLayout. This class is in turn used by the ButtonBarFactory that provides an even higher level of abstraction for building consistent button bars.

Buttons added to the builder are either gridded or fixed and may fill their FormLayout cell or not. All gridded buttons get the same width, while fixed button use their own size. Gridded buttons honor the default minimum button width as specified by the current LayoutStyle.

A button can optionally be declared as narrow, so that it has narrow margins if displayed with a JGoodies look&feel. This is useful if you want to layout buttons with equal width even if a button has a large label. For example, in a bar with 'Add...', 'Remove', 'Properties...' you may declare the properties button to use narrow margins.

Example:
The following example builds a button bar with Help button on the left-hand side and OK, Cancel, Apply buttons on the right-hand side.

 private JPanel createHelpOKCancelApplyBar(
         JButton help, JButton ok, JButton cancel, JButton apply) {
     ButtonBarBuilder builder = new ButtonBarBuilder();
     builder.addGridded(help);
     builder.addRelatedGap();
     builder.addGlue();
     builder.addGriddedButtons(new JButton[]{ok, cancel, apply});
     return builder.getPanel();
 }
 

Version:
$Revision: 1.1 $
Author:
Karsten Lentzsch

Constructor Summary
ButtonBarBuilder()
          Constructs an instance of ButtonBarBuilder on a JPanel.
ButtonBarBuilder(javax.swing.JPanel panel)
          Constructs an instance of ButtonBarBuilder on the given panel.
 
Method Summary
 void addFixed(javax.swing.JComponent component)
          Adds a fixed size component.
 void addFixedNarrow(javax.swing.JComponent component)
          Adds a fixed size component with narrow margins.
 void addGlue()
          Adds a glue that will be given the extra space, if this box is larger than its preferred size.
 void addGridded(javax.swing.JComponent component)
          Adds a gridded component.
 void addGriddedButtons(javax.swing.JButton[] buttons)
          Adds a sequence of related gridded buttons separated by a default gap.
 void addGriddedGrowing(javax.swing.JComponent component)
          Adds a gridded component that grows.
 void addGriddedGrowingButtons(javax.swing.JButton[] buttons)
          Adds a sequence of gridded buttons that grow.
 void addGriddedGrowingNarrow(javax.swing.JComponent component)
          Adds a gridded, narrow component that grows.
 void addGriddedNarrow(javax.swing.JComponent component)
          Deprecated. #addGridded(JComponent) already makes the border narrow
 void addGriddedNarrowButtons(javax.swing.JButton[] buttons)
          Deprecated. #addGriddedButtons already makes the borders narrow
 void addRelatedGap()
          Adds the standard gap for related components.
 void addStrut(ConstantSize size)
          Adds a strut of a specified size.
 void addUnrelatedGap()
          Adds the standard gap for unrelated components.
 void setDefaultButtonBarGapBorder()
          Sets a default border that has a gap in the bar's north.
 
Methods inherited from class com.jgoodies.forms.builder.PanelBuilder
add, addLabel, addLabel, addLabel, addLabel, addSeparator, addSeparator, addSeparator, addSeparator, addTitle, addTitle, addTitle, getPanel, setBorder, setDefaultDialogBorder
 
Methods inherited from class com.jgoodies.forms.builder.AbstractFormBuilder
add, add, add, appendColumn, appendColumn, appendGlueColumn, appendGlueRow, appendRelatedComponentsGapColumn, appendRelatedComponentsGapRow, appendRow, appendRow, appendUnrelatedComponentsGapColumn, appendUnrelatedComponentsGapRow, getColumn, getColumnCount, getContainer, getLayout, getRow, getRowCount, isLeftToRight, nextColumn, nextColumn, nextLine, nextLine, nextRow, nextRow, setAlignment, setBounds, setColumn, setColumnSpan, setExtent, setHAlignment, setLeftToRight, setOrigin, setRow, setRowSpan, setVAlignment
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ButtonBarBuilder

public ButtonBarBuilder(javax.swing.JPanel panel)
Constructs an instance of ButtonBarBuilder on the given panel.

Parameters:
panel - the layout container

ButtonBarBuilder

public ButtonBarBuilder()
Constructs an instance of ButtonBarBuilder on a JPanel.

Method Detail

setDefaultButtonBarGapBorder

public void setDefaultButtonBarGapBorder()
Sets a default border that has a gap in the bar's north.


addGriddedButtons

public void addGriddedButtons(javax.swing.JButton[] buttons)
Adds a sequence of related gridded buttons separated by a default gap.

Parameters:
buttons - an array of buttons to add

addGriddedNarrowButtons

public void addGriddedNarrowButtons(javax.swing.JButton[] buttons)
Deprecated. #addGriddedButtons already makes the borders narrow

Adds a sequence of narrow gridded buttons separated by a default gap.

Parameters:
buttons - an array of buttons to add

addGriddedGrowingButtons

public void addGriddedGrowingButtons(javax.swing.JButton[] buttons)
Adds a sequence of gridded buttons that grow. The buttongs are separated by a default gap.

Parameters:
buttons - an array of buttons to add

addFixed

public void addFixed(javax.swing.JComponent component)
Adds a fixed size component.

Parameters:
component - the component to add

addFixedNarrow

public void addFixedNarrow(javax.swing.JComponent component)
Adds a fixed size component with narrow margins.

Parameters:
component - the component to add

addGridded

public void addGridded(javax.swing.JComponent component)
Adds a gridded component.

Parameters:
component - the component to add

addGriddedNarrow

public void addGriddedNarrow(javax.swing.JComponent component)
Deprecated. #addGridded(JComponent) already makes the border narrow

Adds a gridded narrow component.

Parameters:
component - the component to add

addGriddedGrowing

public void addGriddedGrowing(javax.swing.JComponent component)
Adds a gridded component that grows.

Parameters:
component - the component to add

addGriddedGrowingNarrow

public void addGriddedGrowingNarrow(javax.swing.JComponent component)
Adds a gridded, narrow component that grows.

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.


addUnrelatedGap

public void addUnrelatedGap()
Adds the standard gap for unrelated components.


addStrut

public void addStrut(ConstantSize size)
Adds a strut of a specified size.

Parameters:
size - a ConstantSize that describes the gap's size