com.jgoodies.forms.builder
Class DefaultFormBuilder

java.lang.Object
  extended by com.jgoodies.forms.builder.AbstractBuilder
      extended by com.jgoodies.forms.builder.AbstractFormBuilder
          extended by com.jgoodies.forms.builder.PanelBuilder
              extended by com.jgoodies.forms.builder.I15dPanelBuilder
                  extended by com.jgoodies.forms.builder.DefaultFormBuilder

public final class DefaultFormBuilder
extends I15dPanelBuilder

Provides a means to build form-oriented panels quickly and consistentl using the FormLayout. This builder combines frequently use panel building steps: add a new row, add a label, proceed to the nex data column, then add a component.

#append methods tha append gap rows and component rows if necessary and then ad the given components. They are built upon the superclass behavio #appendRow and the set of #add methods A set of component appenders allows to add a textual label an associated component in a single step.

ResourceBundle in the constructor The builder methods throw an IllegalStateException if on of the mapping builder methods is invoked and no bundle has been set.

AbstractFormBuilderPanelBuilder can do among other things: appending new rows and moving the cursor Again, ask yourself if the DefaultFormBuilder is the appropriate builder As a rule of thumb you should have more components than builder commands There are different ways to add custom rows. Find below example cod that presents and compares the pros and cons of three approaches.

marked texts i.e. strings with an optional mnemonic marker See the MnemonicUtils class comment for details.

Example:

Custom Row Example:

#appendFullSpan and #appendRemaining.

Since:
1.0.3
Version:
$Revision: 1.16 $
Author:
Karsten Lentzsch
See Also:
AbstractFormBuilder, FormSpecs, FormLayout

Field Summary
 
Fields inherited from class com.jgoodies.forms.builder.AbstractBuilder
currentCellConstraints
 
Constructor Summary
DefaultFormBuilder(FormLayout layout)
          Constructs a DefaultFormBuilder for the give layout.
DefaultFormBuilder(FormLayout layout, JPanel container)
          Constructs a DefaultFormBuilder for the give layout and panel.
DefaultFormBuilder(FormLayout layout, ResourceBundle bundle)
          Constructs a DefaultFormBuilder for the give layout and resource bundle.
DefaultFormBuilder(FormLayout layout, ResourceBundle bundle, JPanel container)
          Constructs a DefaultFormBuilder for the give layout, resource bundle, and panel.
DefaultFormBuilder(FormLayout layout, com.jgoodies.common.internal.StringLocalizer localizer)
          Constructs a DefaultFormBuilder for the give layout and resource bundle.
DefaultFormBuilder(FormLayout layout, com.jgoodies.common.internal.StringLocalizer localizer, JPanel container)
          Constructs a DefaultFormBuilder for the give layout, resource bundle, and panel.
 
Method Summary
 void append(Component component)
          Adds a component to the panel using the default constraint with a column span of 1.
 void append(Component c1, Component c2)
          Adds two components to the panel; each component will span a singl data column.
 void append(Component c1, Component c2, Component c3)
          Adds three components to the panel; each component will span a singl data column.
 void append(Component component, int columnSpan)
          Adds a component to the panel using the default constraints wit the given columnSpan.
 JLabel append(String textWithMnemonic)
          Adds a text label to the panel and proceeds to the next column.
 JLabel append(String textWithMnemonic, Component component)
          Adds a text label and component to the panel.
 JLabel append(String textWithMnemonic, Component c, boolean nextLine)
          Adds a text label and component to the panel; the component will spa the specified number columns.
 JLabel append(String textWithMnemonic, Component c1, Component c2)
          Adds a text label and two components to the panel; each componen will span a single column.
 JLabel append(String textWithMnemonic, Component c1, Component c2, Component c3)
          Adds a text label and three components to the panel; each componen will span a single column.
 JLabel append(String textWithMnemonic, Component c1, Component c2, Component c3, Component c4)
          Adds a text label and four components to the panel; each componen will span a single column.
 JLabel append(String textWithMnemonic, Component c1, Component c2, int colSpan)
          Adds a text label and two components to the panel; each componen will span a single column.
 JLabel append(String textWithMnemonic, Component c, int columnSpan)
          Adds a text label and component to the panel; the component will spa the specified number columns.
 JLabel appendI15d(String resourceKey)
          Adds an internationalized (i15d) text label to the panel usin the given resource key and proceeds to the next column.
 JLabel appendI15d(String resourceKey, Component component)
          Adds an internationalized (i15d) text label and componen to the panel.
 JLabel appendI15d(String resourceKey, Component component, boolean nextLine)
          Adds an internationalized (i15d) text label and componen to the panel.
 JLabel appendI15d(String resourceKey, Component c1, Component c2)
          Adds an internationalized (i15d) text label and two component to the panel; each component will span a single column.
 JLabel appendI15d(String resourceKey, Component c1, Component c2, Component c3)
          Adds an internationalized (i15d) text label and three component to the panel; each component will span a single column.
 JLabel appendI15d(String resourceKey, Component c1, Component c2, Component c3, Component c4)
          Adds an internationalized (i15d) text label and four component to the panel; each component will span a single column.
 JLabel appendI15d(String resourceKey, Component c1, Component c2, int colSpan)
          Adds an internationalized (i15d) text label and two component to the panel; each component will span a single column.
 JLabel appendI15d(String resourceKey, Component c, int columnSpan)
          Adds an internationalized (i15d) text label to the panel usin the given resource key; then proceeds to the next data colum and adds a component with the given column span.
 JComponent appendI15dSeparator(String resourceKey)
          Appends an internationalized titled separator fo the given resource key that spans all columns.
 JLabel appendI15dTitle(String resourceKey)
          Adds an internationalized title label to the panel an proceeds to the next column.
 void appendLineGapRow()
          Appends a row with this builder's line gap size.
 JComponent appendSeparator()
          Adds a separator without text that spans all columns.
 JComponent appendSeparator(String text)
          Adds a separator with the given text that spans all columns.
 JLabel appendTitle(String textWithMnemonic)
          Adds a title label to the panel and proceeds to the next column.
 DefaultFormBuilder background(Color background)
          Sets the panel's background color and the panel to be opaque.
 DefaultFormBuilder border(Border border)
          Sets the panel's border.
 DefaultFormBuilder border(String emptyBorderSpec)
          Sets the panel's border as an EmptyBorder using the given specificatio for the top, left, bottom, right in DLU.
 DefaultFormBuilder defaultRowSpec(RowSpec defaultRowSpec)
          Sets the row specification that shall be used for component rows.
 RowSpec getDefaultRowSpec()
          Deprecated. Obsolete; will be deleted from the next version
protected  int getLeadingColumn()
          Returns the leading column.
 int getLeadingColumnOffset()
          Deprecated. Obsolete; will be deleted from the next version
 RowSpec getLineGapSpec()
          Deprecated. Obsolete; will be deleted from the next version
 boolean isRowGroupingEnabled()
          Deprecated. Obsolete; will be deleted from the next version
 DefaultFormBuilder leadingColumnOffset(int columnOffset)
          Sets the offset of the leading column, often 0 or 1.
 DefaultFormBuilder lineGapSize(ConstantSize lineGapSize)
          Sets the size of gaps between component lines using the give constant size.
 DefaultFormBuilder opaque(boolean b)
          Sets the panel's opaque state.
 DefaultFormBuilder paragraphGapSize(ConstantSize paragraphGapSize)
          Sets the size of gaps between paragraphs using the give constant size.
 DefaultFormBuilder rowGroupingEnabled(boolean enabled)
          Enables or disables the grouping of new data rows.
 void setDefaultRowSpec(RowSpec defaultRowSpec)
          Deprecated. Replaced by defaultRowSpec(RowSpec)
 void setLeadingColumnOffset(int columnOffset)
          Deprecated. Replaced by leadingColumnOffset(int)
 void setLineGapSize(ConstantSize lineGapSize)
          Deprecated. Replaced by lineGapSize(ConstantSize)
 void setParagraphGapSize(ConstantSize paragraphGapSize)
          Deprecated. Replaced by lineGapSize(ConstantSize)
 void setRowGroupingEnabled(boolean enabled)
          Deprecated. Replaced by rowGroupingEnabled(boolean)
 
Methods inherited from class com.jgoodies.forms.builder.I15dPanelBuilder
addI15dLabel, addI15dLabel, addI15dLabel, addI15dROLabel, addI15dROLabel, addI15dROLabel, addI15dSeparator, addI15dSeparator, addI15dTitle, addI15dTitle, focusTraversal, getI15dString, isDebugToolTipsEnabled, setDebugToolTipsEnabled
 
Methods inherited from class com.jgoodies.forms.builder.PanelBuilder
add, add, addLabel, addLabel, addLabel, addLabel, addROLabel, addROLabel, addROLabel, addROLabel, addSeparator, addSeparator, addSeparator, addSeparator, addTitle, addTitle, addTitle, build, getLabelForFeatureEnabledDefault, getOpaqueDefault, getPanel, isLabelForApplicable, labelForFeatureEnabled, setBorder, setDefaultDialogBorder, setLabelFor, setLabelForFeatureEnabledDefault, setOpaque, setOpaqueDefault
 
Methods inherited from class com.jgoodies.forms.builder.AbstractFormBuilder
add, add, appendColumn, appendColumn, appendGlueColumn, appendGlueRow, appendLabelComponentsGapColumn, appendParagraphGapRow, appendRelatedComponentsGapColumn, appendRelatedComponentsGapRow, appendRow, appendRow, appendUnrelatedComponentsGapColumn, appendUnrelatedComponentsGapRow, cellConstraints, createLeftAdjustedConstraints, getColumn, getColumnIncrementSign, getRow, isLeftToRight, nextColumn, nextColumn, nextLine, nextLine, nextRow, nextRow, setAlignment, setBounds, setColumn, setColumnSpan, setExtent, setHAlignment, setLeftToRight, setOrigin, setRow, setRowSpan, setVAlignment
 
Methods inherited from class com.jgoodies.forms.builder.AbstractBuilder
createComponentFactory, getColumnCount, getComponentFactory, getComponentFactoryDefault, getContainer, getLayout, getRowCount, setComponentFactory, setComponentFactoryDefault
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFormBuilder

public DefaultFormBuilder(FormLayout layout)
Constructs a DefaultFormBuilder for the give layout.

Parameters:
layout - the FormLayout to be used
Throws:
NullPointerException - if layout is null

DefaultFormBuilder

public DefaultFormBuilder(FormLayout layout,
                          JPanel container)
Constructs a DefaultFormBuilder for the give layout and panel.

Parameters:
layout - the FormLayout to be used
container - the layout container
Throws:
NullPointerException - if layout or container is null

DefaultFormBuilder

public DefaultFormBuilder(FormLayout layout,
                          ResourceBundle bundle)
Constructs a DefaultFormBuilder for the give layout and resource bundle.

Parameters:
layout - the FormLayout to be used
bundle - the ResourceBundle used to lookup i15 strings
Throws:
NullPointerException - if layout is null

DefaultFormBuilder

public DefaultFormBuilder(FormLayout layout,
                          ResourceBundle bundle,
                          JPanel container)
Constructs a DefaultFormBuilder for the give layout, resource bundle, and panel.

Parameters:
layout - the FormLayout to be used
container - the layout container
bundle - the ResourceBundle used to lookup i15 strings
Throws:
NullPointerException - if layout or container is null

DefaultFormBuilder

public DefaultFormBuilder(FormLayout layout,
                          com.jgoodies.common.internal.StringLocalizer localizer)
Constructs a DefaultFormBuilder for the give layout and resource bundle.

Parameters:
layout - the FormLayout to be used
localizer - used to lookup i15d strings
Throws:
NullPointerException - if layout is null

DefaultFormBuilder

public DefaultFormBuilder(FormLayout layout,
                          com.jgoodies.common.internal.StringLocalizer localizer,
                          JPanel container)
Constructs a DefaultFormBuilder for the give layout, resource bundle, and panel.

Parameters:
layout - the FormLayout to be used
container - the layout container
localizer - used to lookup i15d strings
Throws:
NullPointerException - if layout or container is null
Method Detail

background

public DefaultFormBuilder background(Color background)
Description copied from class: PanelBuilder
Sets the panel's background color and the panel to be opaque.

Overrides:
background in class I15dPanelBuilder
Parameters:
background - the color to set as new background
See Also:
JComponent.setBackground(Color)

border

public DefaultFormBuilder border(Border border)
Description copied from class: PanelBuilder
Sets the panel's border.

Overrides:
border in class I15dPanelBuilder
Parameters:
border - the border to set
See Also:
JComponent.setBorder(Border)

border

public DefaultFormBuilder border(String emptyBorderSpec)
Description copied from class: PanelBuilder
Sets the panel's border as an EmptyBorder using the given specificatio for the top, left, bottom, right in DLU. For exampl "1dlu, 2dlu, 3dlu, 4dlu" sets an empty border with 1dlu in the top 2dlu in the left side, 3dlu at the bottom, and 4dlu in the right han side.

setBorder(Borders.createEmptyBorder(emptyBorderSpec)).

Overrides:
border in class I15dPanelBuilder
Parameters:
emptyBorderSpec - describes the top, left, bottom, right size of the EmptyBorder to create
See Also:
Borders.createEmptyBorder(String)

opaque

public DefaultFormBuilder opaque(boolean b)
Description copied from class: PanelBuilder
Sets the panel's opaque state.

Overrides:
opaque in class I15dPanelBuilder
Parameters:
b - true for opaque, false for non-opaque
See Also:
JComponent.setOpaque(boolean)

defaultRowSpec

public DefaultFormBuilder defaultRowSpec(RowSpec defaultRowSpec)
Sets the row specification that shall be used for component rows It is FormSpecs.PREF_ROWSPEC by default.

Parameters:
defaultRowSpec - the RowSpec to be used for component rows

lineGapSize

public DefaultFormBuilder lineGapSize(ConstantSize lineGapSize)
Sets the size of gaps between component lines using the give constant size.

Examples:

Parameters:
lineGapSize - the ConstantSize that describe the size of the gaps between component lines

paragraphGapSize

public DefaultFormBuilder paragraphGapSize(ConstantSize paragraphGapSize)
Sets the size of gaps between paragraphs using the give constant size.

Examples:

Parameters:
paragraphGapSize - the ConstantSize that describe the size of the gaps between paragraphs

leadingColumnOffset

public DefaultFormBuilder leadingColumnOffset(int columnOffset)
Sets the offset of the leading column, often 0 or 1.

Parameters:
columnOffset - the new offset of the leading column

rowGroupingEnabled

public DefaultFormBuilder rowGroupingEnabled(boolean enabled)
Enables or disables the grouping of new data rows.

Parameters:
enabled - indicates grouping enabled, false disabled

getDefaultRowSpec

@Deprecated
public RowSpec getDefaultRowSpec()
Deprecated. Obsolete; will be deleted from the next version

Returns the row specification that is used for component rows.

Returns:
the RowSpec used for component rows
Since:
1.2

setDefaultRowSpec

@Deprecated
public void setDefaultRowSpec(RowSpec defaultRowSpec)
Deprecated. Replaced by defaultRowSpec(RowSpec)

Sets the row specification that shall be used for component rows It is FormSpecs.PREF_ROWSPEC by default.

Parameters:
defaultRowSpec - the RowSpec to be used for component rows
Since:
1.2

getLineGapSpec

@Deprecated
public RowSpec getLineGapSpec()
Deprecated. Obsolete; will be deleted from the next version

Returns the row specification that is used to separate component row.

Returns:
the RowSpec that is used to separate component rows

setLineGapSize

@Deprecated
public void setLineGapSize(ConstantSize lineGapSize)
Deprecated. Replaced by lineGapSize(ConstantSize)

Sets the size of gaps between component lines using the give constant size.

Examples:

Parameters:
lineGapSize - the ConstantSize that describe the size of the gaps between component lines

setParagraphGapSize

@Deprecated
public void setParagraphGapSize(ConstantSize paragraphGapSize)
Deprecated. Replaced by lineGapSize(ConstantSize)

Sets the size of gaps between paragraphs using the give constant size.

Examples:

Parameters:
paragraphGapSize - the ConstantSize that describe the size of the gaps between paragraphs

getLeadingColumnOffset

@Deprecated
public int getLeadingColumnOffset()
Deprecated. Obsolete; will be deleted from the next version

Returns the offset of the leading column, often 0 or 1.

Returns:
the offset of the leading column

setLeadingColumnOffset

@Deprecated
public void setLeadingColumnOffset(int columnOffset)
Deprecated. Replaced by leadingColumnOffset(int)

Sets the offset of the leading column, often 0 or 1.

Parameters:
columnOffset - the new offset of the leading column

isRowGroupingEnabled

@Deprecated
public boolean isRowGroupingEnabled()
Deprecated. Obsolete; will be deleted from the next version

Returns whether new data rows are being grouped or not.

Returns:
true indicates grouping enabled, false disabled

setRowGroupingEnabled

@Deprecated
public void setRowGroupingEnabled(boolean enabled)
Deprecated. Replaced by rowGroupingEnabled(boolean)

Enables or disables the grouping of new data rows.

Parameters:
enabled - indicates grouping enabled, false disabled

appendLineGapRow

public final void appendLineGapRow()
Appends a row with this builder's line gap size.

See Also:
lineGapSize(ConstantSize), AbstractFormBuilder.appendRow(String)

append

public void append(Component component)
Adds a component to the panel using the default constraint with a column span of 1. Then proceeds to the next data column.

Parameters:
component - the component to add

append

public void append(Component component,
                   int columnSpan)
Adds a component to the panel using the default constraints wit the given columnSpan. Proceeds to the next data column.

Parameters:
component - the component to append
columnSpan - the column span used to add

append

public void append(Component c1,
                   Component c2)
Adds two components to the panel; each component will span a singl data column. Proceeds to the next data column.

Parameters:
c1 - the first component to add
c2 - the second component to add

append

public void append(Component c1,
                   Component c2,
                   Component c3)
Adds three components to the panel; each component will span a singl data column. Proceeds to the next data column.

Parameters:
c1 - the first component to add
c2 - the second component to add
c3 - the third component to add

append

public JLabel append(String textWithMnemonic)
Adds a text label to the panel and proceeds to the next column.

Parameters:
textWithMnemonic - the label's text - may mark a mnemonic
Returns:
the added label

append

public JLabel append(String textWithMnemonic,
                     Component component)
Adds a text label and component to the panel Then proceeds to the next data column.

Parameters:
textWithMnemonic - the label's text - may mark a mnemonic
component - the component to add
Returns:
the added label

append

public JLabel append(String textWithMnemonic,
                     Component c,
                     boolean nextLine)
Adds a text label and component to the panel; the component will spa the specified number columns. Proceeds to the next data column and goes to the next line if the boolean flag is set.

Parameters:
textWithMnemonic - the label's text - may mark a mnemonic
c - the component to add
nextLine - true forces a next line
Returns:
the added label
See Also:
JLabel.setLabelFor(java.awt.Component)

append

public JLabel append(String textWithMnemonic,
                     Component c,
                     int columnSpan)
Adds a text label and component to the panel; the component will spa the specified number columns. Proceeds to the next data column.

Parameters:
textWithMnemonic - the label's text - may mark a mnemonic
c - the component to add
columnSpan - number of columns the component shall span
Returns:
the added label
See Also:
JLabel.setLabelFor(java.awt.Component)

append

public JLabel append(String textWithMnemonic,
                     Component c1,
                     Component c2)
Adds a text label and two components to the panel; each componen will span a single column. Proceeds to the next data column.

Parameters:
textWithMnemonic - the label's text - may mark a mnemonic
c1 - the first component to add
c2 - the second component to add
Returns:
the added label

append

public JLabel append(String textWithMnemonic,
                     Component c1,
                     Component c2,
                     int colSpan)
Adds a text label and two components to the panel; each componen will span a single column. Proceeds to the next data column.

Parameters:
textWithMnemonic - the label's text - may mark a mnemonic
c1 - the first component to add
c2 - the second component to add
colSpan - the column span for the second component
Returns:
the created label

append

public JLabel append(String textWithMnemonic,
                     Component c1,
                     Component c2,
                     Component c3)
Adds a text label and three components to the panel; each componen will span a single column. Proceeds to the next data column.

Parameters:
textWithMnemonic - the label's text - may mark a mnemonic
c1 - the first component to add
c2 - the second component to add
c3 - the third component to add
Returns:
the added label

append

public JLabel append(String textWithMnemonic,
                     Component c1,
                     Component c2,
                     Component c3,
                     Component c4)
Adds a text label and four components to the panel; each componen will span a single column. Proceeds to the next data column.

Parameters:
textWithMnemonic - the label's text - may mark a mnemonic
c1 - the first component to add
c2 - the second component to add
c3 - the third component to add
c4 - the fourth component to add
Returns:
the added label

appendI15d

public JLabel appendI15d(String resourceKey)
Adds an internationalized (i15d) text label to the panel usin the given resource key and proceeds to the next column.

Parameters:
resourceKey - the resource key for the the label's text
Returns:
the added label

appendI15d

public JLabel appendI15d(String resourceKey,
                         Component component)
Adds an internationalized (i15d) text label and componen to the panel. Then proceeds to the next data column.

Parameters:
resourceKey - the resource key for the text to add
component - the component to add
Returns:
the added label

appendI15d

public JLabel appendI15d(String resourceKey,
                         Component component,
                         boolean nextLine)
Adds an internationalized (i15d) text label and componen to the panel. Then proceeds to the next data column Goes to the next line if the boolean flag is set.

Parameters:
resourceKey - the resource key for the text to add
component - the component to add
nextLine - true forces a next line
Returns:
the added label

appendI15d

public JLabel appendI15d(String resourceKey,
                         Component c,
                         int columnSpan)
Adds an internationalized (i15d) text label to the panel usin the given resource key; then proceeds to the next data colum and adds a component with the given column span Proceeds to the next data column.

Parameters:
resourceKey - the resource key for the text to add
c - the component to add
columnSpan - number of columns the component shall span
Returns:
the added label

appendI15d

public JLabel appendI15d(String resourceKey,
                         Component c1,
                         Component c2)
Adds an internationalized (i15d) text label and two component to the panel; each component will span a single column Proceeds to the next data column.

Parameters:
resourceKey - the resource key for the text to add
c1 - the first component to add
c2 - the second component to add
Returns:
the added label

appendI15d

public JLabel appendI15d(String resourceKey,
                         Component c1,
                         Component c2,
                         int colSpan)
Adds an internationalized (i15d) text label and two component to the panel; each component will span a single column Proceeds to the next data column.

Parameters:
resourceKey - the resource key for the text to add
c1 - the first component to add
c2 - the second component to add
colSpan - the column span for the second component
Returns:
the added label

appendI15d

public JLabel appendI15d(String resourceKey,
                         Component c1,
                         Component c2,
                         Component c3)
Adds an internationalized (i15d) text label and three component to the panel; each component will span a single column Proceeds to the next data column.

Parameters:
resourceKey - the resource key for the text to add
c1 - the first component to add
c2 - the second component to add
c3 - the third component to add
Returns:
the added label

appendI15d

public JLabel appendI15d(String resourceKey,
                         Component c1,
                         Component c2,
                         Component c3,
                         Component c4)
Adds an internationalized (i15d) text label and four component to the panel; each component will span a single column Proceeds to the next data column.

Parameters:
resourceKey - the resource key for the text to add
c1 - the first component to add
c2 - the second component to add
c3 - the third component to add
c4 - the third component to add
Returns:
the added label

appendTitle

public JLabel appendTitle(String textWithMnemonic)
Adds a title label to the panel and proceeds to the next column.

Parameters:
textWithMnemonic - the label's text - may mark a mnemonic
Returns:
the added title label

appendI15dTitle

public JLabel appendI15dTitle(String resourceKey)
Adds an internationalized title label to the panel an proceeds to the next column.

Parameters:
resourceKey - the resource key for the title's text
Returns:
the added title label

appendSeparator

public JComponent appendSeparator()
Adds a separator without text that spans all columns.

Returns:
the added titled separator

appendSeparator

public JComponent appendSeparator(String text)
Adds a separator with the given text that spans all columns.

Parameters:
text - the separator title text
Returns:
the added titled separator

appendI15dSeparator

public JComponent appendI15dSeparator(String resourceKey)
Appends an internationalized titled separator fo the given resource key that spans all columns.

Parameters:
resourceKey - the resource key for the separator title's text
Returns:
the added titled separator

getLeadingColumn

protected int getLeadingColumn()
Returns the leading column. Unlike the superclass this metho honors the column offset.

Overrides:
getLeadingColumn in class AbstractFormBuilder
Returns:
the leading column


Copyright © 2002-2013 JGoodies Software GmbH. All Rights Reserved.