Logo Search packages:      
Sourcecode: libjgoodies-forms-java version File versions  Download package

com::jgoodies::forms::builder::ButtonBarBuilder Class Reference

Inheritance diagram for com::jgoodies::forms::builder::ButtonBarBuilder:

com::jgoodies::forms::builder::PanelBuilder com::jgoodies::forms::builder::AbstractFormBuilder

List of all members.


Detailed Description

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 com.jgoodies.forms.factories.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 buttons use their own size. Gridded buttons honor the default minimum button width as specified by the current com.jgoodies.forms.util.LayoutStyle.

You can set an optional hint for narrow margin for the fixed width buttons. This is useful if you want to lay out a button bar that includes a button with a long text. For example, in a bar with 'Copy to Clipboard', 'OK', 'Cancel' you may declare the clipboard button as a fixed size button with narrow margins, OK and Cancel as gridded. Gridded buttons are marked as narrow by default. 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.

To honor the platform's button order (left-to-right vs. right-to-left) this builder uses the leftToRightButtonOrder property. It is initialized with the current LayoutStyle's button order, which in turn is left-to-right on most platforms and right-to-left on the Mac OS X. Builder methods that create sequences of buttons (e.g. addGriddedButtons(JButton[]) honor the button order. If you want to ignore the default button order, you can either add add individual buttons, or create a ButtonBarBuilder instance with the order set to left-to-right. For the latter see createLeftToRightBuilder(). Also see the button order example below.

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();
 }
 

Button Order Example:
The following example builds three button bars where one honors the platform's button order and the other two ignore it.

 public JComponent buildPanel() {
     FormLayout layout = new FormLayout("pref");
     DefaultFormBuilder rowBuilder = new DefaultFormBuilder(layout);
     rowBuilder.setDefaultDialogBorder();

     rowBuilder.append(buildButtonSequence(new ButtonBarBuilder()));
     rowBuilder.append(buildButtonSequence(ButtonBarBuilder.createLeftToRightBuilder()));
     rowBuilder.append(buildIndividualButtons(new ButtonBarBuilder()));

     return rowBuilder.getPanel();
 }

 private Component buildButtonSequence(ButtonBarBuilder builder) {
     builder.addGriddedButtons(new JButton[] {
             new JButton("One"),
             new JButton("Two"),
             new JButton("Three")
     });
     return builder.getPanel();
 }

 private Component buildIndividualButtons(ButtonBarBuilder builder) {
     builder.addGridded(new JButton("One"));
     builder.addRelatedGap();
     builder.addGridded(new JButton("Two"));
     builder.addRelatedGap();
     builder.addGridded(new JButton("Three"));
     return builder.getPanel();
 }
 

Author:
Karsten Lentzsch
Version:
Revision
1.10

See also:
ButtonStackBuilder

com.jgoodies.forms.factories.ButtonBarFactory

com.jgoodies.forms.util.LayoutStyle

Definition at line 137 of file ButtonBarBuilder.java.


Public Member Functions

final Component add (Component component)
final Component add (Component component, String encodedCellConstraints)
final Component add (Component component, CellConstraints cellConstraints)
final JLabel add (JLabel label, CellConstraints labelConstraints, Component component, CellConstraints componentConstraints)
void addFixed (JComponent component)
void addFixedNarrow (JComponent component)
void addGlue ()
void addGridded (JComponent component)
void addGriddedButtons (JButton[] buttons)
void addGriddedGrowing (JComponent component)
void addGriddedGrowingButtons (JButton[] buttons)
final JLabel addLabel (String textWithMnemonic, CellConstraints labelConstraints, Component component, CellConstraints componentConstraints)
final JLabel addLabel (String textWithMnemonic)
final JLabel addLabel (String textWithMnemonic, String encodedConstraints)
final JLabel addLabel (String textWithMnemonic, CellConstraints constraints)
void addRelatedGap ()
final JComponent addSeparator (String text)
final JComponent addSeparator (String text, int columnSpan)
final JComponent addSeparator (String text, String encodedConstraints)
final JComponent addSeparator (String text, CellConstraints constraints)
void addStrut (ConstantSize size)
final JLabel addTitle (String text)
final JLabel addTitle (String text, String encodedConstraints)
final JLabel addTitle (String text, CellConstraints constraints)
void addUnrelatedGap ()
final void appendColumn (String encodedColumnSpec)
final void appendColumn (ColumnSpec columnSpec)
final void appendGlueColumn ()
final void appendGlueRow ()
final void appendLabelComponentsGapColumn ()
final void appendParagraphGapRow ()
final void appendRelatedComponentsGapColumn ()
final void appendRelatedComponentsGapRow ()
final void appendRow (String encodedRowSpec)
final void appendRow (RowSpec rowSpec)
final void appendUnrelatedComponentsGapColumn ()
final void appendUnrelatedComponentsGapRow ()
 ButtonBarBuilder (JPanel panel)
 ButtonBarBuilder ()
final int getColumn ()
final int getColumnCount ()
final Container getContainer ()
final FormLayout getLayout ()
final JPanel getPanel ()
final int getRow ()
final int getRowCount ()
final boolean isLeftToRight ()
boolean isLeftToRightButtonOrder ()
final void nextColumn (int columns)
final void nextColumn ()
final void nextLine (int lines)
final void nextLine ()
final void nextRow (int rows)
final void nextRow ()
final void setAlignment (CellConstraints.Alignment hAlign, CellConstraints.Alignment vAlign)
final void setBorder (Border border)
final void setBounds (int column, int row, int columnSpan, int rowSpan)
final void setColumn (int column)
final void setColumnSpan (int columnSpan)
final void setComponentFactory (ComponentFactory newFactory)
void setDefaultButtonBarGapBorder ()
final void setDefaultDialogBorder ()
final void setExtent (int columnSpan, int rowSpan)
final void setHAlignment (CellConstraints.Alignment alignment)
final void setLeftToRight (boolean b)
void setLeftToRightButtonOrder (boolean newButtonOrder)
final void setOrigin (int column, int row)
final void setRow (int row)
final void setRowSpan (int rowSpan)
final void setVAlignment (CellConstraints.Alignment alignment)

Static Public Member Functions

static ButtonBarBuilder createLeftToRightBuilder ()

Protected Member Functions

final CellConstraints cellConstraints ()
final CellConstraints createLeftAdjustedConstraints (int columnSpan)
final int getColumnIncrementSign ()
final ComponentFactory getComponentFactory ()
int getLeadingColumn ()

Private Attributes

boolean leftToRight

Static Private Attributes

static final ColumnSpec[] COL_SPECS
static final String NARROW_KEY = "jgoodies.isNarrow"
static final RowSpec[] ROW_SPECS

The documentation for this class was generated from the following file:

Generated by  Doxygen 1.6.0   Back to index