com.jgoodies.forms.builder
Class PanelBuilder

java.lang.Object
  extended by com.jgoodies.forms.builder.AbstractFormBuilder
      extended by com.jgoodies.forms.builder.PanelBuilder
Direct Known Subclasses:
ButtonBarBuilder, ButtonStackBuilder

public class PanelBuilder
extends AbstractFormBuilder

An general purpose panel builder that uses the FormLayout to layout JPanels. It provides convenience methods to set a default border and to add labels, titles and titled separators.

The PanelBuilder is the working horse for layouts when more specialized builders like the ButtonBarBuilder or com.jgoodies.forms.extras.DefaultFormBuilder are inappropriate.

The Forms tutorial includes several examples that present and compare different style to build with the PanelBuilder: static row numbers vs. row variable, explicit CellConstraints vs. builder cursor, static rows vs. dynamically added rows. Also, you may check out the Tips & Tricks section of the Forms HTML documentation.

Example:
This example creates a panel with 3 columns and 3 rows.

 FormLayout layout = new FormLayout(
      "right:pref, 6dlu, 50dlu, 4dlu, default",  // columns 
      "pref, 3dlu, pref, 3dlu, pref");           // rows

 PanelBuilder builder = new PanelBuilder(layout);
 CellConstraints cc = new CellConstraints();
 builder.addLabel("Label1",      cc.xy  (1, 1));
 builder.add(new JTextField(),   cc.xywh(3, 1, 3, 1));
 builder.addLabel("Label2",      cc.xy  (1, 3));
 builder.add(new JTextField(),   cc.xy  (3, 3));
 builder.addLabel("Label3",      cc.xy  (1, 5));
 builder.add(new JTextField(),   cc.xy  (3, 5));
 builder.add(new JButton("..."), cc.xy  (5, 5));
 return builder.getPanel();
 

Version:
$Revision: 1.1 $
Author:
Karsten Lentzsch
See Also:
com.jgoodies.forms.extras.I15dPanelBuilder, com.jgoodies.forms.extras.DefaultFormBuilder

Constructor Summary
PanelBuilder(FormLayout layout)
          Constructs an instance of PanelBuilder for the given layout.
PanelBuilder(javax.swing.JPanel panel, FormLayout layout)
          Constructs an instance of PanelBuilder for the given panel and layout.
 
Method Summary
 javax.swing.JLabel add(javax.swing.JLabel label, CellConstraints labelConstraints, java.awt.Component component, CellConstraints componentConstraints)
          Adds a label and component to the panel using the given cell constraints.
 javax.swing.JLabel addLabel(java.lang.String textWithMnemonic)
          Adds a textual label to the form using the default constraints.
 javax.swing.JLabel addLabel(java.lang.String textWithMnemonic, CellConstraints constraints)
          Adds a textual label to the form using the specified constraints.
 javax.swing.JLabel addLabel(java.lang.String textWithMnemonic, CellConstraints labelConstraints, java.awt.Component component, CellConstraints componentConstraints)
          Adds a label and component to the panel using the given cell constraints.
 javax.swing.JLabel addLabel(java.lang.String textWithMnemonic, java.lang.String encodedConstraints)
          Adds a textual label to the form using the specified constraints.
 javax.swing.JComponent addSeparator(java.lang.String text)
          Adds a titled separator to the form that spans all columns.
 javax.swing.JComponent addSeparator(java.lang.String text, CellConstraints constraints)
          Adds a titled separator to the form using the specified constraints.
 javax.swing.JComponent addSeparator(java.lang.String text, int columnSpan)
          Adds a titled separator to the form that spans the specified columns.
 javax.swing.JComponent addSeparator(java.lang.String text, java.lang.String encodedConstraints)
          Adds a titled separator to the form using the specified constraints.
 javax.swing.JLabel addTitle(java.lang.String text)
          Adds a title label to the form using the default constraints.
 javax.swing.JLabel addTitle(java.lang.String text, CellConstraints constraints)
          Adds a title label to the form using the specified constraints.
 javax.swing.JLabel addTitle(java.lang.String text, java.lang.String encodedConstraints)
          Adds a title label to the form using the specified constraints.
 javax.swing.JPanel getPanel()
          Returns the panel used to build the form.
 void setBorder(javax.swing.border.Border border)
          Sets the panel's border.
 void setDefaultDialogBorder()
          Sets the default dialog border.
 
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

PanelBuilder

public PanelBuilder(javax.swing.JPanel panel,
                    FormLayout layout)
Constructs an instance of PanelBuilder for the given panel and layout.

Parameters:
panel - the layout container to build on
layout - the form layout to use

PanelBuilder

public PanelBuilder(FormLayout layout)
Constructs an instance of PanelBuilder for the given layout. Uses an instance of JPanel as layout container.

Parameters:
layout - the form layout to use
Method Detail

getPanel

public final javax.swing.JPanel getPanel()
Returns the panel used to build the form.


setBorder

public final void setBorder(javax.swing.border.Border border)
Sets the panel's border.

Parameters:
border - the border to set

setDefaultDialogBorder

public final void setDefaultDialogBorder()
Sets the default dialog border.


addLabel

public final javax.swing.JLabel addLabel(java.lang.String textWithMnemonic,
                                         CellConstraints constraints)
Adds a textual label to the form using the specified constraints.

Parameters:
textWithMnemonic - the label's text - may contain a mnemonic marker
constraints - the label's cell constraints
Returns:
the new label

addLabel

public final javax.swing.JLabel addLabel(java.lang.String textWithMnemonic,
                                         java.lang.String encodedConstraints)
Adds a textual label to the form using the specified constraints.

Parameters:
textWithMnemonic - the label's text - may contain a mnemonic marker
encodedConstraints - a string representation for the constraints
Returns:
the new label

addLabel

public final javax.swing.JLabel addLabel(java.lang.String textWithMnemonic)
Adds a textual label to the form using the default constraints.

Parameters:
textWithMnemonic - the label's text - may contain a mnemonic marker
Returns:
the new label

add

public final javax.swing.JLabel add(javax.swing.JLabel label,
                                    CellConstraints labelConstraints,
                                    java.awt.Component component,
                                    CellConstraints componentConstraints)
Adds a label and component to the panel using the given cell constraints. Sets the given label as the component label using Label#setLabelFor.

Parameters:
label - the label to add
labelConstraints - the label's cell constraints
component - the component to add
componentConstraints - the component's cell constraints
Returns:
the added label
See Also:
JLabel.setLabelFor(java.awt.Component)

addLabel

public final javax.swing.JLabel addLabel(java.lang.String textWithMnemonic,
                                         CellConstraints labelConstraints,
                                         java.awt.Component component,
                                         CellConstraints componentConstraints)
Adds a label and component to the panel using the given cell constraints. Sets the given label as the component label using Label#setLabelFor.

Parameters:
textWithMnemonic - the label's text - may contain a mnemonic marker
labelConstraints - the label's cell constraints
component - the component to add
componentConstraints - the component's cell constraints
Returns:
the added label
See Also:
JLabel.setLabelFor(java.awt.Component)

addTitle

public final javax.swing.JLabel addTitle(java.lang.String text,
                                         CellConstraints constraints)
Adds a title label to the form using the specified constraints.

Parameters:
text - the label's title text
constraints - the separator's cell constraints
Returns:
the added title label

addTitle

public final javax.swing.JLabel addTitle(java.lang.String text,
                                         java.lang.String encodedConstraints)
Adds a title label to the form using the specified constraints.

Parameters:
text - the label's text
encodedConstraints - a string representation for the constraints
Returns:
the added title label

addTitle

public final javax.swing.JLabel addTitle(java.lang.String text)
Adds a title label to the form using the default constraints.

Parameters:
text - the separator titel
Returns:
the added title label

addSeparator

public final javax.swing.JComponent addSeparator(java.lang.String text,
                                                 CellConstraints constraints)
Adds a titled separator to the form using the specified constraints.

Parameters:
text - the separator title
constraints - the separator's cell constraints
Returns:
the added separator

addSeparator

public final javax.swing.JComponent addSeparator(java.lang.String text,
                                                 java.lang.String encodedConstraints)
Adds a titled separator to the form using the specified constraints.

Parameters:
text - the separator titel
encodedConstraints - a string representation for the constraints
Returns:
the added separator

addSeparator

public final javax.swing.JComponent addSeparator(java.lang.String text,
                                                 int columnSpan)
Adds a titled separator to the form that spans the specified columns.

Parameters:
text - the separator titel
columnSpan - the number of columns the separator spans
Returns:
the added separator

addSeparator

public final javax.swing.JComponent addSeparator(java.lang.String text)
Adds a titled separator to the form that spans all columns.

Parameters:
text - the separator titel
Returns:
the added separator