| java.lang.Object com.jgoodies.forms.builder.AbstractFormBuilder com.jgoodies.forms.builder.PanelBuilder com.jgoodies.forms.builder.I15dPanelBuilder com.jgoodies.forms.builder.DefaultFormBuilder
DefaultFormBuilder | final public class DefaultFormBuilder extends I15dPanelBuilder (Code) | | Provides a means to build form-oriented panels quickly and consistently using
the
FormLayout . This builder combines frequently used panel building
steps: add a new row, add a label, proceed to the next data column, then add
a component.
The extra value lies in the #append methods that append gap
rows and component rows if necessary and then add the given components. They
are built upon the superclass behavior #appendRow and the set
of #add methods. A set of component appenders allows to add a
textual label and associated component in a single step.
This builder can map resource keys to internationalized (i15d) texts when
creating text labels, titles and titled separators. Therefore you must
specify a ResourceBundle in the constructor. The builder
methods throw an IllegalStateException if one of the mapping
builder methods is invoked and no bundle has been set.
You can configure the build process by setting a leading column, enabling the
row grouping and by modifying the gaps between normal lines and between
paragraphs. The leading column will be honored if the cursor proceeds to the
next row. All appended components start in the specified lead column, except
appended separators that span all columns.
It is temptive to use the DefaultFormBuilder all the time and to let it add
rows automatically. Use a simpler style if it increases the code readability.
Explicit row specifications and cell constraints make your layout easier to
understand - but harder to maintain. See also the accompanying tutorial
sources and the Tips & Tricks that are part of the Forms documentation.
Sometimes a form consists of many standardized rows but has a few rows that
require a customization. The DefaultFormBuilder can do everything that the
superclasses
com.jgoodies.forms.builder.AbstractFormBuilder and
com.jgoodies.forms.builder.PanelBuilder 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 code that presents and compares the pros and
cons of three approaches.
The texts used in methods #append(String, ...) and
#appendTitle(String) as well as the localized texts used in
methods #appendI15d and #appendI15dTitle can
contain an optional mnemonic marker. The mnemonic and mnemonic index are
indicated by a single ampersand (&). For example
"&Save", or "Save &as".
To use the ampersand itself, duplicate it, for example
"Look&&Feel".
Example:
public void build() {
FormLayout layout = new FormLayout("right:max(40dlu;pref), 3dlu, 80dlu, 7dlu, " // 1st major colum
+ "right:max(40dlu;pref), 3dlu, 80dlu", // 2nd major column
""); // add rows dynamically
DefaultFormBuilder builder = new DefaultFormBuilder(layout);
builder.setDefaultDialogBorder();
builder.appendSeparator("Flange");
builder.append("Identifier", identifierField);
builder.nextLine();
builder.append("PTI [kW]", new JTextField());
builder.append("Power [kW]", new JTextField());
builder.append("s [mm]", new JTextField());
builder.nextLine();
builder.appendSeparator("Diameters");
builder.append("da [mm]", new JTextField());
builder.append("di [mm]", new JTextField());
builder.append("da2 [mm]", new JTextField());
builder.append("di2 [mm]", new JTextField());
builder.append("R [mm]", new JTextField());
builder.append("D [mm]", new JTextField());
builder.appendSeparator("Criteria");
builder.append("Location", buildLocationComboBox());
builder.append("k-factor", new JTextField());
builder.appendSeparator("Bolts");
builder.append("Material", ViewerUIFactory.buildMaterialComboBox());
builder.nextLine();
builder.append("Numbers", new JTextField());
builder.nextLine();
builder.append("ds [mm]", new JTextField());
}
Custom Row Example:
public JComponent buildPanel() {
initComponents();
FormLayout layout = new FormLayout("right:pref, 3dlu, default:grow", "");
DefaultFormBuilder builder = new DefaultFormBuilder(layout);
builder.setDefaultDialogBorder();
builder.setRowGroupingEnabled(true);
CellConstraints cc = new CellConstraints();
// In this approach, we add a gap and a custom row.
// The advantage of this approach is, that we can express
// the row spec and comment area cell constraints freely.
// The disadvantage is the misalignment of the leading label.
// Also the row's height may be inconsistent with other rows.
builder.appendSeparator("Single Custom Row");
builder.append("Name", name1Field);
builder.appendRow(builder.getLineGapSpec());
builder.appendRow(new RowSpec("top:31dlu")); // Assumes line is 14, gap is 3
builder.nextLine(2);
builder.append("Comment");
builder.add(new JScrollPane(comment1Area), cc.xy(builder.getColumn(), builder.getRow(), "fill, fill"));
builder.nextLine();
// In this approach, we append a standard row with gap before it.
// The advantage is, that the leading label is aligned well.
// The disadvantage is that the comment area now spans
// multiple cells and is slightly less flexible.
// Also the row's height may be inconsistent with other rows.
builder.appendSeparator("Standard + Custom Row");
builder.append("Name", name2Field);
builder.append("Comment");
builder.appendRow(new RowSpec("17dlu")); // Assumes line is 14, gap is 3
builder.add(new JScrollPane(comment2Area), cc.xywh(builder.getColumn(), builder.getRow(), 1, 2));
builder.nextLine(2);
// In this approach, we append two standard rows with associated gaps.
// The advantage is, that the leading label is aligned well,
// and the height is consistent with other rows.
// The disadvantage is that the comment area now spans
// multiple cells and is slightly less flexible.
builder.appendSeparator("Two Standard Rows");
builder.append("Name", name3Field);
builder.append("Comment");
builder.nextLine();
builder.append("");
builder.nextRow(-2);
builder.add(new JScrollPane(comment3Area), cc.xywh(builder.getColumn(), builder.getRow(), 1, 3));
return builder.getPanel();
}
TODO: Consider adding a method for appending a component that spans the
remaining columns in the current row. Method name candidates are
#appendFullSpan and #appendRemaining .
author: Karsten Lentzsch version: $Revision: 1.2 $ since: 1.0.3 See Also: com.jgoodies.forms.builder.AbstractFormBuilder See Also: com.jgoodies.forms.factories.FormFactory See Also: com.jgoodies.forms.layout.FormLayout |
Method Summary | |
public void | append(Component component) Adds a component to the panel using the default constraints with a column
span of 1. | public void | append(Component component, int columnSpan) Adds a component to the panel using the default constraints with the
given columnSpan. | public void | append(Component c1, Component c2) Adds two components to the panel; each component will span a single data
column. | public void | append(Component c1, Component c2, Component c3) Adds three components to the panel; each component will span a single
data column. | public JLabel | append(String textWithMnemonic) Adds a text label to the panel and proceeds to the next column. | public JLabel | append(String textWithMnemonic, Component component) Adds a text label and component to the panel. | public JLabel | append(String textWithMnemonic, Component c, int columnSpan) Adds a text label and component to the panel; the component will span the
specified number columns. | public JLabel | append(String textWithMnemonic, Component c1, Component c2) Adds a text label and two components to the panel; each component will
span a single column. | public void | append(String textWithMnemonic, Component c1, Component c2, int colSpan) Adds a text label and two components to the panel; each component will
span a single column. | public JLabel | append(String textWithMnemonic, Component c1, Component c2, Component c3) Adds a text label and three components to the panel; each component will
span a single column. | public JLabel | append(String textWithMnemonic, Component c1, Component c2, Component c3, Component c4) Adds a text label and four components to the panel; each component will
span a single column. | public JLabel | appendI15d(String resourceKey) Adds an internationalized (i15d) text label to the panel using the given
resource key and proceeds to the next column. | public JLabel | appendI15d(String resourceKey, Component c, int columnSpan) Adds an internationalized (i15d) text label to the panel using the given
resource key; then proceeds to the next data column and adds a component
with the given column span. | public JLabel | appendI15d(String resourceKey, Component component) Adds an internationalized (i15d) text label and component to the panel. | public JLabel | appendI15d(String resourceKey, Component component, boolean nextLine) Adds an internationalized (i15d) text label and component to the panel.
Then proceeds to the next data column. | public JLabel | appendI15d(String resourceKey, Component c1, Component c2) Adds an internationalized (i15d) text label and two components to the
panel; each component will span a single column. | public JLabel | appendI15d(String resourceKey, Component c1, Component c2, int colSpan) Adds an internationalized (i15d) text label and two components to the
panel; each component will span a single column. | public JLabel | appendI15d(String resourceKey, Component c1, Component c2, Component c3) Adds an internationalized (i15d) text label and three components to the
panel; each component will span a single column. | public JLabel | appendI15d(String resourceKey, Component c1, Component c2, Component c3, Component c4) Adds an internationalized (i15d) text label and four components to the
panel; each component will span a single column. | public void | appendI15dSeparator(String resourceKey) Appends an internationalized titled separator for the given resource key
that spans all columns. | public JLabel | appendI15dTitle(String resourceKey) Adds an internationalized title label to the panel and proceeds to the
next column. | public JComponent | appendSeparator() Adds a separator without text that spans all columns. | public JComponent | appendSeparator(String text) Adds a separator with the given text that spans all columns. | public JLabel | appendTitle(String textWithMnemonic) Adds a title label to the panel and proceeds to the next column. | protected int | getLeadingColumn() Returns the leading column. | public int | getLeadingColumnOffset() Returns the offset of the leading column, often 0 or 1. | public RowSpec | getLineGapSpec() Returns the row specification that is used to separate component lines. | public boolean | isRowGroupingEnabled() Returns whether new data rows are being grouped or not. | public void | setLeadingColumnOffset(int columnOffset) Sets the offset of the leading column, often 0 or 1. | public void | setLineGapSize(ConstantSize lineGapSize) Sets the size of gaps between component lines using the given constant
size. | public void | setParagraphGapSize(ConstantSize paragraphGapSize) Sets the size of gaps between paragraphs using the given constant size. | public void | setRowGroupingEnabled(boolean enabled) Enables or disables the grouping of new data rows. |
DefaultFormBuilder | public DefaultFormBuilder(FormLayout layout)(Code) | | Constructs an instance of DefaultFormBuilder for the given
layout.
Parameters: layout - the FormLayout to be used |
DefaultFormBuilder | public DefaultFormBuilder(FormLayout layout, JPanel panel)(Code) | | Constructs an instance of DefaultFormBuilder for the given
panel and layout.
Parameters: layout - the FormLayout to be used Parameters: panel - the layout container |
DefaultFormBuilder | public DefaultFormBuilder(FormLayout layout, ResourceBundle bundle)(Code) | | Constructs an instance of DefaultFormBuilder for the given
layout and resource bundle.
Parameters: layout - the FormLayout to be used Parameters: bundle - the ResourceBundle used to lookup i15d strings |
DefaultFormBuilder | public DefaultFormBuilder(FormLayout layout, ResourceBundle bundle, JPanel panel)(Code) | | Constructs an instance of DefaultFormBuilder for the given
panel, layout and resource bundle.
Parameters: layout - the FormLayout to be used Parameters: panel - the layout container Parameters: bundle - the ResourceBundle used to lookup i15d strings |
append | public void append(Component component)(Code) | | Adds a component to the panel using the default constraints 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)(Code) | | Adds a component to the panel using the default constraints with the
given columnSpan. Proceeds to the next data column.
Parameters: component - the component to append Parameters: columnSpan - the column span used to add |
append | public void append(Component c1, Component c2)(Code) | | Adds two components to the panel; each component will span a single data
column. Proceeds to the next data column.
Parameters: c1 - the first component to add Parameters: c2 - the second component to add |
append | public void append(Component c1, Component c2, Component c3)(Code) | | Adds three components to the panel; each component will span a single
data column. Proceeds to the next data column.
Parameters: c1 - the first component to add Parameters: c2 - the second component to add Parameters: c3 - the third component to add |
append | public JLabel append(String textWithMnemonic)(Code) | | Adds a text label to the panel and proceeds to the next column.
Parameters: textWithMnemonic - the label's text - may mark a mnemonic the added label |
append | public JLabel append(String textWithMnemonic, Component component)(Code) | | 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 Parameters: component - the component to add the added label |
append | public JLabel append(String textWithMnemonic, Component c, int columnSpan)(Code) | | Adds a text label and component to the panel; the component will span the
specified number columns. Proceeds to the next data column.
The created label is labelling the given component; so the component gets
the focus if the (optional) label mnemonic is pressed.
Parameters: textWithMnemonic - the label's text - may mark a mnemonic Parameters: c - the component to add Parameters: columnSpan - number of columns the component shall span the added label See Also: JLabel.setLabelFor(java.awt.Component) |
append | public JLabel append(String textWithMnemonic, Component c1, Component c2)(Code) | | Adds a text label and two components to the panel; each component will
span a single column. Proceeds to the next data column.
Parameters: textWithMnemonic - the label's text - may mark a mnemonic Parameters: c1 - the first component to add Parameters: c2 - the second component to add the added label |
append | public void append(String textWithMnemonic, Component c1, Component c2, int colSpan)(Code) | | Adds a text label and two components to the panel; each component will
span a single column. Proceeds to the next data column.
Parameters: textWithMnemonic - the label's text - may mark a mnemonic Parameters: c1 - the first component to add Parameters: c2 - the second component to add Parameters: colSpan - the column span for the second component |
append | public JLabel append(String textWithMnemonic, Component c1, Component c2, Component c3)(Code) | | Adds a text label and three components to the panel; each component will
span a single column. Proceeds to the next data column.
Parameters: textWithMnemonic - the label's text - may mark a mnemonic Parameters: c1 - the first component to add Parameters: c2 - the second component to add Parameters: c3 - the third component to add the added label |
append | public JLabel append(String textWithMnemonic, Component c1, Component c2, Component c3, Component c4)(Code) | | Adds a text label and four components to the panel; each component will
span a single column. Proceeds to the next data column.
Parameters: textWithMnemonic - the label's text - may mark a mnemonic Parameters: c1 - the first component to add Parameters: c2 - the second component to add Parameters: c3 - the third component to add Parameters: c4 - the fourth component to add the added label |
appendI15d | public JLabel appendI15d(String resourceKey)(Code) | | Adds an internationalized (i15d) text label to the panel using the given
resource key and proceeds to the next column.
Parameters: resourceKey - the resource key for the the label's text the added label |
appendI15d | public JLabel appendI15d(String resourceKey, Component c, int columnSpan)(Code) | | Adds an internationalized (i15d) text label to the panel using the given
resource key; then proceeds to the next data column 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 Parameters: c - the component to add Parameters: columnSpan - number of columns the component shall span the added label |
appendI15d | public JLabel appendI15d(String resourceKey, Component component)(Code) | | Adds an internationalized (i15d) text label and component to the panel.
Then proceeds to the next data column.
Parameters: resourceKey - the resource key for the text to add Parameters: component - the component to add the added label |
appendI15d | public JLabel appendI15d(String resourceKey, Component component, boolean nextLine)(Code) | | Adds an internationalized (i15d) text label and component 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 Parameters: component - the component to add Parameters: nextLine - true forces a next line the added label |
appendI15d | public JLabel appendI15d(String resourceKey, Component c1, Component c2)(Code) | | Adds an internationalized (i15d) text label and two components 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 Parameters: c1 - the first component to add Parameters: c2 - the second component to add the added label |
appendI15d | public JLabel appendI15d(String resourceKey, Component c1, Component c2, int colSpan)(Code) | | Adds an internationalized (i15d) text label and two components 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 Parameters: c1 - the first component to add Parameters: c2 - the second component to add Parameters: colSpan - the column span for the second component the added label |
appendI15d | public JLabel appendI15d(String resourceKey, Component c1, Component c2, Component c3)(Code) | | Adds an internationalized (i15d) text label and three components 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 Parameters: c1 - the first component to add Parameters: c2 - the second component to add Parameters: c3 - the third component to add the added label |
appendI15d | public JLabel appendI15d(String resourceKey, Component c1, Component c2, Component c3, Component c4)(Code) | | Adds an internationalized (i15d) text label and four components 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 Parameters: c1 - the first component to add Parameters: c2 - the second component to add Parameters: c3 - the third component to add Parameters: c4 - the third component to add the added label |
appendI15dSeparator | public void appendI15dSeparator(String resourceKey)(Code) | | Appends an internationalized titled separator for the given resource key
that spans all columns.
Parameters: resourceKey - the resource key for the separator title's text |
appendI15dTitle | public JLabel appendI15dTitle(String resourceKey)(Code) | | Adds an internationalized title label to the panel and proceeds to the
next column.
Parameters: resourceKey - the resource key for the title's text the added title label |
appendSeparator | public JComponent appendSeparator()(Code) | | Adds a separator without text that spans all columns.
the added titled separator |
appendSeparator | public JComponent appendSeparator(String text)(Code) | | Adds a separator with the given text that spans all columns.
Parameters: text - the separator title text the added titled separator |
appendTitle | public JLabel appendTitle(String textWithMnemonic)(Code) | | Adds a title label to the panel and proceeds to the next column.
Parameters: textWithMnemonic - the label's text - may mark a mnemonic the added title label |
getLeadingColumn | protected int getLeadingColumn()(Code) | | Returns the leading column. Unlike the superclass this method honors the
column offset.
the leading column |
getLeadingColumnOffset | public int getLeadingColumnOffset()(Code) | | Returns the offset of the leading column, often 0 or 1.
the offset of the leading column |
getLineGapSpec | public RowSpec getLineGapSpec()(Code) | | Returns the row specification that is used to separate component lines.
the RowSpec that is used to separate lines |
isRowGroupingEnabled | public boolean isRowGroupingEnabled()(Code) | | Returns whether new data rows are being grouped or not.
true indicates grouping enabled, false disabled |
setLeadingColumnOffset | public void setLeadingColumnOffset(int columnOffset)(Code) | | Sets the offset of the leading column, often 0 or 1.
Parameters: columnOffset - the new offset of the leading column |
setLineGapSize | public void setLineGapSize(ConstantSize lineGapSize)(Code) | | Sets the size of gaps between component lines using the given constant
size.
Examples:
builder.setLineGapSize(Sizes.ZERO);
builder.setLineGapSize(Sizes.DLUY9);
builder.setLineGapSize(Sizes.pixel(1));
Parameters: lineGapSize - the ConstantSize that describes the size of thegaps between component lines |
setParagraphGapSize | public void setParagraphGapSize(ConstantSize paragraphGapSize)(Code) | | Sets the size of gaps between paragraphs using the given constant size.
Examples:
builder.setParagraphGapSize(Sizes.DLUY14);
builder.setParagraphGapSize(Sizes.dluY(22));
builder.setParagraphGapSize(Sizes.pixel(42));
Parameters: paragraphGapSize - the ConstantSize that describes the size of thegaps between paragraphs |
setRowGroupingEnabled | public void setRowGroupingEnabled(boolean enabled)(Code) | | Enables or disables the grouping of new data rows.
Parameters: enabled - indicates grouping enabled, false disabled |
Methods inherited from com.jgoodies.forms.builder.PanelBuilder | final public JLabel add(JLabel label, CellConstraints labelConstraints, Component component, CellConstraints componentConstraints)(Code)(Java Doc) final public JLabel addLabel(String textWithMnemonic, CellConstraints constraints)(Code)(Java Doc) final public JLabel addLabel(String textWithMnemonic, String encodedConstraints)(Code)(Java Doc) final public JLabel addLabel(String textWithMnemonic)(Code)(Java Doc) final public JLabel addLabel(String textWithMnemonic, CellConstraints labelConstraints, Component component, CellConstraints componentConstraints)(Code)(Java Doc) final public JComponent addSeparator(String text, CellConstraints constraints)(Code)(Java Doc) final public JComponent addSeparator(String text, String encodedConstraints)(Code)(Java Doc) final public JComponent addSeparator(String text, int columnSpan)(Code)(Java Doc) final public JComponent addSeparator(String text)(Code)(Java Doc) final public JLabel addTitle(String text, CellConstraints constraints)(Code)(Java Doc) final public JLabel addTitle(String text, String encodedConstraints)(Code)(Java Doc) final public JLabel addTitle(String text)(Code)(Java Doc) final protected ComponentFactory getComponentFactory()(Code)(Java Doc) final public JPanel getPanel()(Code)(Java Doc) final public void setBorder(Border border)(Code)(Java Doc) final public void setComponentFactory(ComponentFactory newFactory)(Code)(Java Doc) final public void setDefaultDialogBorder()(Code)(Java Doc)
|
|
|