public class FormBuilder extends Object
FormLayout
to lay out and populate JPanel
s. It provides the following features:
true
.focusTraversalType
vs.
focusTraversalPolicy
.
The FormBuilder is the working horse
for forms and panels where more specialized builders such as the
ListViewBuilder
or the ButtonBarBuilder
are inappropriate.
Since FormBuilder supports the frequently used methods for setting up
and configuring a FormLayout, the vast majority of forms can be built
with just the FormBuilder. In other words, you will typically not
work with FormLayout instances directly.
Forms are built as a two-step process: first, you setup and configure the layout, then add the components.
Example: (creates a panel with 3 columns and 3 rows)
return FormBuilder.create() .columns("left:pref, $lcgap, 50dlu, $rgap, default") .rows("p, $lg, p, $lg, p") .padding(Paddings.DIALOG) .add("&Title:") .xy (1, 1) .add(titleField) .xywh(3, 1, 3, 1) .add("&Price:") .xy (1, 3) .add(priceField) .xy (3, 3) .add("&Author:") .xy (1, 5) .add(authorField) .xy (3, 5) .add(browseButton).xy (5, 5) .build();FormBuilder provides convenience methods for adding labels, titles, and titled separators. These components will be created by the builder's component factory that can be set via
factory(ComponentFactory)
,
and that is by default initialized from
FormsSetup.getComponentFactoryDefault()
.
The text arguments passed to the methods #addLabel
,
#addTitle
, and #addSeparator
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".
Feature Overview:
.columns("pref, $lcgap, %sdlu, p, p", "50") // Format string .columnGroup(4, 5) // Grouping short hand .debug(true) // Installs FormDebugPanel .add("Title:") .xy(1, 1) // Implicitly created label .add("&Price:") .xy(1, 1) // Label with mnemonic .add(hasCountry, combo).xy(3, 1) // Conditional adding .add(aTable) .xywh(1, 1, 3, 5) // Auto-wrapped with scrollpane .addScrolled(aTextArea).xywh(1, 1, 1, 3) // scrollpane shorthand .addBar(newBtn, editBtn, deleteBtn).xy(1, 5) // button bar .addBar(landscapeRadio, portraitRadio).xy(1, 1) // Radio button bar
FormLayout
Modifier and Type | Class and Description |
---|---|
static class |
FormBuilder.ComponentAdder |
static interface |
FormBuilder.FormBuildingView
Describes a view that can be integrated into an existing form
using
add(FormBuildingView) . |
static class |
FormBuilder.LabelType |
static class |
FormBuilder.ViewAdder |
Modifier | Constructor and Description |
---|---|
protected |
FormBuilder() |
Modifier and Type | Method and Description |
---|---|
FormBuilder.ComponentAdder |
add(boolean expression,
Component c)
The first of two steps for conditionally adding a component to the form.
|
FormBuilder.ViewAdder |
add(boolean expression,
FormBuilder.FormBuildingView view)
Builds the given view into this FormBuilder's form,
if
expression is true . |
FormBuilder.ComponentAdder |
add(boolean expression,
Icon image)
The first of two steps for conditionally adding an icon label to the form.
|
FormBuilder.ComponentAdder |
add(boolean expression,
String markedLabelText,
Object... args)
The first of two steps for conditionally adding a textual label
to the form.
|
FormBuilder.ComponentAdder |
add(Component c)
The first of two steps for adding a component to this builder's panel.
|
FormBuilder.ViewAdder |
add(FormBuilder.FormBuildingView view)
Builds the given view into this FormBuilder's form.
|
FormBuilder.ComponentAdder |
add(Icon image)
The first of two steps for adding an icon label to the form.
|
FormBuilder.ComponentAdder |
add(String markedLabelText,
Object... args)
The first of two steps for adding a textual label to the form.
|
FormBuilder.ComponentAdder |
addBar(boolean expression,
JButton... buttons)
The first of two steps for conditionally adding a button bar to the form.
|
FormBuilder.ComponentAdder |
addBar(boolean expression,
JCheckBox... checkBoxes)
The first of two steps for conditionally adding a check box bar to the form.
|
FormBuilder.ComponentAdder |
addBar(boolean expression,
JRadioButton... radioButtons)
The first of two steps for conditionally adding a radio button bar
to this builder's panel.
|
FormBuilder.ComponentAdder |
addBar(JButton... buttons)
The first of two steps for adding a button bar to this builder's panel.
|
FormBuilder.ComponentAdder |
addBar(JCheckBox... checkBoxes)
The first of two steps for adding a check box bar to this builder's panel.
|
FormBuilder.ComponentAdder |
addBar(JRadioButton... radioButtons)
The first of two steps for adding a radio button bar to this builder's panel.
|
protected FormBuilder.ComponentAdder |
addImpl(Component c) |
FormBuilder.ComponentAdder |
addLabel(boolean expression,
String markedText,
Object... args)
The first of two steps for conditionally adding a plain label to the form.
|
FormBuilder.ComponentAdder |
addLabel(String markedText,
Object... args)
The first of two steps for adding a plain label to the form.
|
FormBuilder.ComponentAdder |
addRaw(boolean expression,
Component c)
The first of two steps for conditionally adding a component to the form.
|
FormBuilder.ComponentAdder |
addRaw(Component c)
The first of two steps for adding a component to this builder's panel.
|
FormBuilder.ComponentAdder |
addROLabel(boolean expression,
String markedText,
Object... args)
The first of two steps for conditionally adding a textual label to the form
that is intended for labeling read-only components.
|
FormBuilder.ComponentAdder |
addROLabel(String markedText,
Object... args)
The first of two steps for adding a textual label to the form
that is intended for labeling read-only components.
|
FormBuilder.ComponentAdder |
addScrolled(boolean expression,
Component c)
The first of two steps for conditionally adding the given component
wrapped with a JScrollPane to this builder's panel.
|
FormBuilder.ComponentAdder |
addScrolled(Component c)
The first of two steps for adding the given component wrapped
with a JScrollPane to this builder's panel.
|
FormBuilder.ComponentAdder |
addSeparator(boolean expression,
String markedText,
Object... args)
The first of two steps for conditionally adding a titled separator to the form.
|
FormBuilder.ComponentAdder |
addSeparator(String markedText,
Object... args)
The first of two steps for adding a titled separator to the form.
|
FormBuilder.ComponentAdder |
addStack(boolean expression,
JButton... buttons)
The first of two steps for conditionally adding a button stack
to this builder's panel.
|
FormBuilder.ComponentAdder |
addStack(boolean expression,
JCheckBox... checkBoxes)
The first of two steps for conditionally adding a check box stack
to this builder's panel.
|
FormBuilder.ComponentAdder |
addStack(boolean expression,
JRadioButton... radioButtons)
The first of two steps for conditionally adding a radio button stack
to this builder's panel.
|
FormBuilder.ComponentAdder |
addStack(JButton... buttons)
The first of two steps for adding a button stack to this builder's panel.
|
FormBuilder.ComponentAdder |
addStack(JCheckBox... checkBoxes)
The first of two steps for adding a check box stack to this builder's panel.
|
FormBuilder.ComponentAdder |
addStack(JRadioButton... radioButtons)
The first of two steps for adding a radio button stack to this builder's panel.
|
FormBuilder.ComponentAdder |
addTitle(boolean expression,
String markedText,
Object... args)
The first of two steps for conditionally adding a title label to the form.
|
FormBuilder.ComponentAdder |
addTitle(String markedText,
Object... args)
The first of two steps for adding a title label to the form.
|
FormBuilder |
appendColumns(String encodedColumnSpecs,
Object... args)
Appends the given columns to this builder's layout.
|
FormBuilder |
appendRows(String encodedRowSpecs,
Object... args)
Appends the given rows to this builder's layout.
|
FormBuilder |
background(Color background)
Sets the panel's background color and the panel to be opaque.
|
FormBuilder |
border(Border border)
Sets the panel's border.
|
FormBuilder |
border(String paddingSpec)
Deprecated.
Use
padding(String, Object...) instead |
JPanel |
build()
Returns the panel used to build the form.
|
FormBuilder |
columnGroup(int... columnIndices)
Configures this builder's layout to group (make equally wide)
the columns with the given indices.
|
FormBuilder |
columnGroups(int[]... multipleColumnGroups)
Configures this builder's layout to group (make equally wide)
the columns per array of column indices.
|
FormBuilder |
columns(String encodedColumnSpecs,
Object... args)
Configures this builder's layout columns using a comma-separated
string of column specifications.
|
static FormBuilder |
create()
Creates and return a new FormBuilder instance.
|
FormBuilder |
debug(boolean b)
Enables or disables the display of layout debug information.
|
FormBuilder |
defaultLabelType(FormBuilder.LabelType newValue)
Sets a new value for the default label type that is used to determine
whether
add(String, Object...) delegates to
addLabel(String, Object...) |
FormBuilder |
factory(ComponentFactory factory)
Sets
factory as this builder's new component factory
that is used when adding implicitly created components such as
labels, titles, or titled separators. |
FormBuilder |
focusGroup(AbstractButton... buttons)
Tries to build a focus group for the given buttons.
|
FormBuilder |
focusTraversalPolicy(FocusTraversalPolicy policy)
Sets the panel's focus traversal policy and sets the panel
as focus traversal policy provider.
|
FormBuilder |
focusTraversalType(FocusTraversalType focusTraversalType)
Sets either a layout or container order focus traversal policy.
|
protected ComponentFactory |
getFactory() |
protected FormLayout |
getLayout() |
protected LayoutMap |
getLayoutMap() |
JPanel |
getPanel()
Returns the panel used to build the form.
|
FormBuilder |
honorsVisibility(boolean b)
Specifies whether invisible components shall be taken into account by
this builder for computing the layout size and setting component bounds.
|
FormBuilder |
honorsVisibility(JComponent c,
boolean b)
Configures how this builder's layout shall handle the visibility
of the given component.
|
FormBuilder |
initialComponent(JComponent initialComponent)
Sets a component that should receive the focus when a Window is
made visible for the first time.
|
FormBuilder |
labelForFeatureEnabled(boolean b)
Enables or disables the setLabelFor feature for this builder.
|
FormBuilder |
layout(FormLayout layout)
Sets
layout as the layout to use by this builder. |
FormBuilder |
layoutMap(LayoutMap layoutMap)
Configures this builder's FormLayout to use the given layout map
for expanding layout variables.
|
FormBuilder |
name(String panelName)
Sets the name of the panel this builder works with.
|
FormBuilder |
offset(int offsetX,
int offsetY)
When adding components, the cell constraints origin are moved
along the X and Y axis using an offset
as specified by
offsetX and offsetY respectively. |
FormBuilder |
opaque(boolean b)
Sets the panel's opaque state.
|
FormBuilder |
padding(EmptyBorder padding)
Sets the panel's padding, an empty border.
|
FormBuilder |
padding(String paddingSpec,
Object... args)
Sets the panel's padding as an EmptyBorder using the given specification
for the top, left, bottom, right margins in DLU.
|
FormBuilder |
panel(JPanel panel)
Sets
panel as the panel that this builder shall work with. |
FormBuilder |
rowGroup(int... rowIndices)
Configures this builder's layout to group (make equally high)
the rows with the given indices.
|
FormBuilder |
rowGroups(int[]... multipleRowGroups)
Configures this builder's layout to group (make equally wide)
the rows per array of row indices.
|
FormBuilder |
rows(String encodedRowSpecs,
Object... args)
Configures this builder's layout rows using a comma-separated
string of row specifications.The string can be a format string
and will then use the optional format arguments, see
String.format(String, Object...) . |
FormBuilder |
translate(int dX,
int dY)
Moves the cell constraints offset along the X and Y axis
as specified by
dx and dy respectively. |
public static FormBuilder create()
public JPanel build()
public FormBuilder layoutMap(LayoutMap layoutMap)
Example:
return FormBuilder.create() .columns("left:pref, $lcgap, 200dlu") .rows("p, $lg, p, $lg, p") .layoutMap(aCustomLayoutMap) ...
layoutMap
- expands layout column and row variablespublic FormBuilder columns(String encodedColumnSpecs, Object... args)
String.format(String, Object...)
.
Examples:
.columns("left:90dlu, 3dlu, 200dlu") .columns("left:90dlu, 3dlu, %sdlu", "200") // Format string .columns("$label, $lcgap, 200dlu") // Layout variables
encodedColumnSpecs
- a comma-separated list of column specificationsargs
- optional format argumentsColumnSpec
public FormBuilder appendColumns(String encodedColumnSpecs, Object... args)
String.format(String, Object...)
.
Examples:
.appendColumns("50dlu, 3dlu, 50dlu") .appendColumns("%sdlu, 3dlu, %sdlu", "50") // Format string .appendColumns("$button, $rgap, $button") // Layout variable
encodedColumnSpecs
- a comma-separated list of column specificationsargs
- optional format argumentsColumnSpec
public FormBuilder rows(String encodedRowSpecs, Object... args)
String.format(String, Object...)
.
Examples:
.rows("p, 3dlu, p, 14dlu, p") .rows("p, 3dlu, p, %sdlu, p", "14") // Format string .rows("p, $pg, p, $pg, p") // Layout variables
encodedRowSpecs
- a comma-separated list of row specificationsargs
- optional format argumentsRowSpec
public FormBuilder appendRows(String encodedRowSpecs, Object... args)
String.format(String, Object...)
.
Examples:
.appendRows("10dlu, p, 3dlu, p") .appendRows("%sdlu, p, 3dlu, p", "10") // Format string .appendRows("10dlu, p, $lg, p") // Layout variable
encodedRowSpecs
- a comma-separated list of row specificationsargs
- optional format argumentsRowSpec
public FormBuilder columnGroup(int... columnIndices)
Examples:
.columnGroup(3, 5)
columnIndices
- the indices of the columns to grouppublic FormBuilder columnGroups(int[]... multipleColumnGroups)
Examples:
.columnGroups(new int[]{3, 5}, new int[]{7, 9})
multipleColumnGroups
- multiple arrays of column indicespublic FormBuilder rowGroup(int... rowIndices)
Examples:
.rowGroup(3, 5)
rowIndices
- the indices of the rows to grouppublic FormBuilder rowGroups(int[]... multipleRowGroups)
Examples:
.rowGroups(new int[]{3, 5}, new int[]{7, 9})
multipleRowGroups
- multiple arrays of row indicespublic FormBuilder honorsVisibility(boolean b)
true
invisible components will be ignored by
the layout. If set to false
components will be taken into
account regardless of their visibility. Visible components are always
used for sizing and positioning.
The default value for this setting is true
.
It is useful to set the value to false
(in other words
to ignore the visibility) if you switch the component visibility
dynamically and want the container to retain the size and
component positions.
b
- true
to honor the visibility, i.e. to exclude
invisible components from the sizing and positioning,
false
to ignore the visibility, in other words to
layout visible and invisible componentsFormLayout.setHonorsVisibility(boolean)
public FormBuilder honorsVisibility(JComponent c, boolean b)
c
- the component to configureb
- true
to use c
for layout computations only if visible,
false
to take c
into account even if invisibleFormLayout.setHonorsVisibility(Component, Boolean)
public FormBuilder layout(FormLayout layout)
layout
as the layout to use by this builder.layout
- the layout to be used by this builderpublic FormBuilder panel(JPanel panel)
panel
as the panel that this builder shall work with.panel
- the panel to work withpublic FormBuilder debug(boolean b)
b
- true
to paint grid lines, false
to disable itFormDebugPanel
public FormBuilder name(String panelName)
panelName
- the name to setpublic FormBuilder background(Color background)
background
- the color to set as new backgroundJComponent.setBackground(Color)
public FormBuilder border(Border border)
padding(EmptyBorder)
instead.border
- the border to setpadding(EmptyBorder)
,
JComponent.setBorder(Border)
@Deprecated public FormBuilder border(String paddingSpec)
padding(String, Object...)
instead
Equivalent to setPadding(Paddings.createPadding(paddingSpec))
.
paddingSpec
- describes the top, left, bottom, right margins
of the padding (an EmptyBorder) to usePaddings.createPadding(String, Object...)
public FormBuilder padding(EmptyBorder padding)
padding
- the white space around this formborder(javax.swing.border.Border)
public FormBuilder padding(String paddingSpec, Object... args)
Equivalent to padding(Paddings.createPadding(paddingSpec, args))
.
paddingSpec
- describes the top, left, bottom, right margins
of the padding (an EmptyBorder) to useargs
- optional format arguments,
used if paddingSpec
is a format stringpadding(EmptyBorder)
,
Paddings.createPadding(String, Object...)
public FormBuilder opaque(boolean b)
b
- true for opaque, false for non-opaqueJComponent.setOpaque(boolean)
public FormBuilder initialComponent(JComponent initialComponent)
FocusTraversalPolicy.getInitialComponent(java.awt.Window)
.initialComponent
- the component that shall receive the focuspublic FormBuilder focusTraversalType(FocusTraversalType focusTraversalType)
JGContainerOrderFocusTraversalPolicy
and
JGLayoutFocusTraversalPolicy
are in the class path,
these will be used. Otherwise the standard Swing
ContainerOrderFocusTraversalPolicy
and
LayoutFocusTraversalPolicy
respectively will be used.focusTraversalType
- specifies the type: layout or container orderNullPointerException
- if focusTraversalType
is null
focusTraversalPolicy(FocusTraversalPolicy)
public FormBuilder focusTraversalPolicy(FocusTraversalPolicy policy)
A call to this method is only necessary, if you set a custom Swing
focus traversal policy other than LayoutFocusTraversalPolicy
or ContainerOrderFocusTraversalPolicy
(or their commercial
replacements JGLayoutFocusTraversalPolicy
or
JGContainerOrderFocusTraversalPolicy
).
Call to this method are equivalent to:
builder.getPanel().setFocusTraversalPolicy(policy); builder.getPanel().setFocusTraversalPolicyProvider(true);
policy
- the focus traversal policy that will manage
keyboard traversal of the children in this builder's panelNullPointerException
- if focusTraversalType
is null
focusTraversalType(FocusTraversalType)
,
Container.setFocusTraversalPolicy(FocusTraversalPolicy)
,
Container.setFocusTraversalPolicyProvider(boolean)
public FormBuilder focusGroup(AbstractButton... buttons)
To succeed, the commercial FocusTraversalUtils
class must be
in the class path. To make focus grouping work, a focus traversal policy
must be set that is capable of transferring focus with the arrow keys
such as JGContainerOrderFocusTraversalPolicy
or
JGLayoutFocusTraversalPolicy
.
buttons
- the buttons to be groupedpublic JPanel getPanel()
build()
instead.build()
public FormBuilder factory(ComponentFactory factory)
factory
as this builder's new component factory
that is used when adding implicitly created components such as
labels, titles, or titled separators.
If not called, the default factory will be used
that can be configured via
FormsSetup.setComponentFactoryDefault(ComponentFactory)
.factory
- the factory to be used to create componentspublic FormBuilder labelForFeatureEnabled(boolean b)
The value is initialized from the global default value
FormsSetup.getLabelForFeatureEnabledDefault()
.
It is globally disabled by default.
b
- true
for enabled, false
for disabledJLabel.setLabelFor(Component)
public FormBuilder offset(int offsetX, int offsetY)
offsetX
and offsetY
respectively.This operation is not cumulative. In other words, setting the offset overrides the previously set offset. For example:
builder .offset(0, 2) .offset(1, 3) .offset(4, 8)ends with an offset of (4, 8).
offsetX
- the distance to move cell constraints along the X axisoffsetY
- the distance to move cell constraints along the Y axistranslate(int, int)
public FormBuilder translate(int dX, int dY)
dx
and dy
respectively.This operation is cumulative for the offset. In other words, every translation is added to all previously set translations. For example:
builder .offset(0, 0) .translate(0, 2) .translate(1, 3) .translate(4, 8)ends with an offset of (5, 13).
dX
- the distance to move the offset along the X axisdY
- the distance to move the offset along the Y axisoffset(int, int)
public FormBuilder defaultLabelType(FormBuilder.LabelType newValue)
add(String, Object...)
delegates to
addLabel(String, Object...)
or addROLabel(String, Object...)
.newValue
- the default label typepublic FormBuilder.ComponentAdder add(Component c)
JTables, JLists, and JTrees will be automatically wrapped
by a default JScrollPane. If no scroll pane is desired, use
addRaw(Component)
instead. If a scroll pane is desired
for other components (frequent case are JTextAreas) use
addScrolled(Component)
.
return FormBuilder.create() ... .add(nameField) .xy(1, 1) .add(countryCombo).xy(3, 3) ... .build();If the label-for-feature is enabled, the most recently added label is tracked and associated with the next added component that is applicable for being set as component for the label.
c
- the component to add; will be wrapped if it is an
instance of JTable, JList, or JTreeisLabelForApplicable(JLabel, Component)
public FormBuilder.ComponentAdder addRaw(Component c)
Unlike add(Component)
, this method won't wrap
JTables, JLists, and JTrees automatically with a JScrollPane.
Useful for tables, list, and trees that either need no scroll pane,
or have another kind of decoration.
return FormBuilder.create() ... .addRaw(aTreeThatNeedsNoScrollPane).xy(1, 1) ... .build();If the label-for-feature is enabled, the most recently added label is tracked and associated with the next added component that is applicable for being set as component for the label.
c
- the component to addisLabelForApplicable(JLabel, Component)
public FormBuilder.ComponentAdder addScrolled(Component c)
The layout is equivalent to:
return FormBuilder.create() ... .add(new JScrollPane(c)).xy(..., ...) ... .build();
c
- the component to be wrapped and addedpublic FormBuilder.ComponentAdder addBar(JButton... buttons)
The buttons will be laid out horizontally in a subpanel, where all buttons use the platform's minimum width. If focus grouping is possible, focus can be transferred between buttons using the arrow keys.
return FormBuilder.create() ... .addBar(newButton, editButton, deleteButton).xy(1, 9) ... .build();
buttons
- the buttons to addForms.buttonBar(JComponent...)
public FormBuilder.ComponentAdder addBar(JCheckBox... checkBoxes)
The check boxes will be laid out as a row in a subpanel. If focus grouping is possible, focus can be transferred between the check boxes using the arrow keys.
return FormBuilder.create() ... .addBar(visibleBox, editableBox, enabledBox).xy(1, 9) ... .build();
checkBoxes
- the check boxes to addForms.checkBoxBar(JCheckBox...)
public FormBuilder.ComponentAdder addBar(JRadioButton... radioButtons)
The radio buttons will be laid out as a row in a subpanel. If focus grouping is possible, focus can be transferred between the radio buttons using the arrow keys. Also, focus will be transferred to/from the selected radio button of the group - if any.
return FormBuilder.create() ... .addBar(verticalRadio, horizontalRadio).xy(1, 9) ... .build();
radioButtons
- the radio buttons to addForms.radioButtonBar(JRadioButton...)
public FormBuilder.ComponentAdder addStack(JButton... buttons)
The buttons will be laid out vertically in a subpanel, where all buttons use the platform's minimum width. If focus grouping is possible, focus can be transferred between buttons using the arrow keys.
return FormBuilder.create() ... .addStack(newButton, editButton, deleteButton).xywh(5, 1, 1, 7) ... .build();
buttons
- the buttons to addForms.buttonStack(JComponent...)
public FormBuilder.ComponentAdder addStack(JCheckBox... checkBoxes)
The check boxes will be laid out vertically in a subpanel. If focus grouping is possible, focus can be transferred between the check boxes using the arrow keys.
return FormBuilder.create() ... .addStack(visibleBox, editableBox, enabledBox).xywh(5, 1, 1, 7) ... .build();
checkBoxes
- the check boxes to addForms.checkBoxStack(JCheckBox...)
public FormBuilder.ComponentAdder addStack(JRadioButton... radioButtons)
The radio buttons will be laid out vertically in a subpanel. If focus grouping is possible, focus can be transferred between the check boxes using the arrow keys. Also, focus will be transferred to/from the selected radio button of the group - if any.
return FormBuilder.create() ... .addStack(verticalRadio, horizontalRadio).xywh(5, 1, 1, 7) ... .build();
radioButtons
- the radio buttons to addForms.radioButtonStack(JRadioButton...)
public FormBuilder.ViewAdder add(FormBuilder.FormBuildingView view)
Note: This is an experimental feature that is not yet part of the public FormBuilder API. It may change without further notice.
view
- the view to integratepublic FormBuilder.ComponentAdder add(String markedLabelText, Object... args)
addLabel(markedLabelText, args)
or addROLabel(markedLabelText, args)
depending on
the current defaultLabelType.
The label will be created and added,
once the cell constraints are specified.
return FormBuilder.create() ... .add("Name:") .xy(1, 1) // No Mnemonic .add("N&ame:") .xy(1, 1) // Mnemonic is 'a' .add("Save &as:") .xy(1, 1) // Mnemonic is the second 'a' .add("Look&&Feel:").xy(1, 1) // No mnemonic, text is "look&feel" ... .build();
markedLabelText
- the text of the label to be added,
may contain an ampersand (&) to mark a mnemonic,
and it may be a format stringargs
- optional format argumentsdefaultLabelType(LabelType)
,
MnemonicUtils
,
String.format(String, Object...)
public FormBuilder.ComponentAdder addLabel(String markedText, Object... args)
return FormBuilder.create() ... .addLabel("Name:") .xy(1, 1) // No Mnemonic .addLabel("N&ame:") .xy(1, 1) // Mnemonic is 'a' .addLabel("Save &as:") .xy(1, 1) // Mnemonic is the second 'a' .addLabel("Look&&Feel:").xy(1, 1) // No mnemonic, text is "look&feel" ... .build();
markedText
- the label's text -
may contain an ampersand (&) to mark a mnemonic,
and it may be a format stringargs
- optional format argumentsMnemonicUtils
,
ComponentFactory
,
String.format(String, Object...)
public FormBuilder.ComponentAdder addROLabel(String markedText, Object... args)
The read-only labels created by the default component factory are slightly lighter than plain labels. This makes it easier to differ between the labeling text and the text value that is labeled.
return FormBuilder.create() ... .addROLabel("Name:") .xy(1, 1) // No Mnemonic .addROLabel("N&ame:") .xy(1, 1) // Mnemonic is 'a' .addROLabel("Save &as:") .xy(1, 1) // Mnemonic is the second 'a' .addROLabel("Look&&Feel:").xy(1, 1) // No mnemonic, text is "look&feel" ... .build();
markedText
- the label's text -
may contain an ampersand (&) to mark a mnemonic,
and it may be a format stringargs
- optional format argumentsMnemonicUtils
,
ComponentFactory
,
String.format(String, Object...)
public FormBuilder.ComponentAdder addTitle(String markedText, Object... args)
return FormBuilder.create() ... .addTitle("Name") .xy(1, 1) // No mnemonic .addTitle("N&ame") .xy(1, 1) // Mnemonic is 'a' .addTitle("Look&&Feel").xy(1, 1) // No mnemonic, text is Look&Feel ... .build();
markedText
- the title label's text -
may contain an ampersand (&) to mark a mnemonic,
and it may be a format stringargs
- optional format argumentsMnemonicUtils
,
ComponentFactory
,
String.format(String, Object...)
public FormBuilder.ComponentAdder addSeparator(String markedText, Object... args)
return FormBuilder.create() ... .addSeparator("Name") .xyw(1, 1, 3) // No Mnemonic .addSeparator("N&ame") .xyw(1, 1, 3) // Mnemonic is 'a' .addSeparator("Look&&Feel").xyw(1, 1, 3) // No mnemonic, text is "look&feel" ... .build();
markedText
- the separator label's text -
may contain an ampersand (&) to mark a mnemonic,
and it may be a format stringargs
- optional format argumentsMnemonicUtils
,
ComponentFactory
,
String.format(String, Object...)
public FormBuilder.ComponentAdder add(Icon image)
image
is null, nothing will be added.image
- the image to be displayed by the added labelJLabel.JLabel(Icon)
public FormBuilder.ComponentAdder add(boolean expression, Component c)
expression
is true
.
JTables, JLists, and JTrees will be automatically wrapped
by a default JScrollPane. If no scroll pane is desired, use
addRaw(boolean, Component)
instead. If a scroll pane is desired
for other components (frequent case are JTextAreas) use
addScrolled(boolean, Component)
.
return FormBuilder.create() ... .add(nameField) .xy(1, 1) .add(hasCountry, countryCombo).xy(3, 3) ... .build();If the label-for-feature is enabled, the most recently added label is tracked and associate with the next added component that is applicable for being set as component for the label.
expression
- the precondition for adding the componentc
- the component to addisLabelForApplicable(JLabel, Component)
public FormBuilder.ComponentAdder addRaw(boolean expression, Component c)
Unlike add(boolean, Component)
, this method won't wrap
JTables, JLists, and JTrees automatically with a JScrollPane.
Useful for tables, list, and trees that either need no scroll pane,
or have another kind of decoration.
return FormBuilder.create() ... .addRaw(showTree, aTreeThatNeedsNoScrollPane).xy(1, 1) ... .build();If the label-for-feature is enabled, the most recently added label is tracked and associated with the next added component that is applicable for being set as component for the label.
expression
- the precondition for adding the componentc
- the component to addisLabelForApplicable(JLabel, Component)
public FormBuilder.ComponentAdder addScrolled(boolean expression, Component c)
The layout is equivalent to:
return FormBuilder.create() ... .add(expression, new JScrollPane(c)).xy(..., ...) ... .build();
expression
- the precondition for adding the componentc
- the component to be wrapped and addedpublic FormBuilder.ComponentAdder addBar(boolean expression, JButton... buttons)
The buttons will be laid out horizontally in a subpanel, where all buttons use the platform's minimum width. If focus grouping is possible, focus can be transferred between buttons using the arrow keys.
return FormBuilder.create() ... .addBar(!readOnly, newButton, editButton, deleteButton).xy(1, 9) ... .build();
expression
- the precondition for adding the barbuttons
- the buttons to addForms.buttonBar(JComponent...)
public FormBuilder.ComponentAdder addBar(boolean expression, JCheckBox... checkBoxes)
The check boxes will be laid out as a row in a subpanel. If focus grouping is possible, focus can be transferred between the check boxes using the arrow keys.
return FormBuilder.create() ... .addBar(!readOnly, visibleBox, editableBox, enabledBox).xy(1, 9) ... .build();
expression
- the precondition for adding the barcheckBoxes
- the check boxes to addForms.checkBoxBar(JCheckBox...)
public FormBuilder.ComponentAdder addBar(boolean expression, JRadioButton... radioButtons)
The radio buttons will be laid out as a row in a subpanel. If focus grouping is possible, focus can be transferred between the radio buttons using the arrow keys. Also, focus will be transferred to/from the selected radio button of the group - if any.
return FormBuilder.create() ... .add ( readOnly, orientationText) .xy(1, 9) .addBar(!readOnly, verticalRadio, horizontalRadio).xy(1, 9) ... .build();
expression
- the precondition for adding the barradioButtons
- the radio buttons to addForms.radioButtonBar(JRadioButton...)
public FormBuilder.ComponentAdder addStack(boolean expression, JButton... buttons)
The buttons will be laid out vertically in a subpanel, where all buttons use the platform's minimum width. If focus grouping is possible, focus can be transferred between buttons using the arrow keys.
return FormBuilder.create() ... .addStack(!readOnly, newButton, editButton, deleteButton).xywh(5, 1, 1, 7) ... .build();
expression
- the precondition for adding the stackbuttons
- the buttons to addForms.buttonStack(JComponent...)
public FormBuilder.ComponentAdder addStack(boolean expression, JCheckBox... checkBoxes)
The check boxes will be laid out vertically in a subpanel. If focus grouping is possible, focus can be transferred between the check boxes using the arrow keys.
return FormBuilder.create() ... .addStack(!readOnly, visibleBox, editableBox, enabledBox).xywh(5, 1, 1, 7) ... .build();
expression
- the precondition for adding the stackcheckBoxes
- the check boxes to addForms.checkBoxStack(JCheckBox...)
public FormBuilder.ComponentAdder addStack(boolean expression, JRadioButton... radioButtons)
The radio buttons will be laid out vertically in a subpanel. If focus grouping is possible, focus can be transferred between the check boxes using the arrow keys. Also, focus will be transferred to/from the selected radio button of the group - if any.
return FormBuilder.create() ... .addStack(!readOnly, verticalRadio, horizontalRadio).xywh(5, 1, 1, 7) ... .build();
expression
- the precondition for adding the stackradioButtons
- the radio buttons to addForms.radioButtonStack(JRadioButton...)
public FormBuilder.ViewAdder add(boolean expression, FormBuilder.FormBuildingView view)
expression
is true
.expression
- the precondition for adding the viewview
- the view to integratepublic FormBuilder.ComponentAdder add(boolean expression, String markedLabelText, Object... args)
addLabel(expression, markedLabelText, args)
or addROLabel(expression, markedLabelText, args)
depending on
the current defaultLabelType.
The label will be created and added,
once the cell constraints are specified.
return FormBuilder.create() ... .add(condition, "Name:") .xy(1, 1) // No Mnemonic .add(condition, "N&ame:") .xy(1, 1) // Mnemonic is 'a' .add(condition, "Save &as:") .xy(1, 1) // Mnemonic is the second 'a' .add(condition, "Look&&Feel:").xy(1, 1) // No mnemonic, text is "look&feel" ... .build();
expression
- the precondition for adding the labelmarkedLabelText
- the text of the label to be added,
may contain an ampersand (&) to mark a mnemonic,
and it may be a format stringargs
- optional format argumentsdefaultLabelType(LabelType)
,
MnemonicUtils
,
ComponentFactory
,
String.format(String, Object...)
public FormBuilder.ComponentAdder addLabel(boolean expression, String markedText, Object... args)
return FormBuilder.create() ... .addLabel(condition, "Name:") .xy(1, 1) // No Mnemonic .addLabel(condition, "N&ame:") .xy(1, 1) // Mnemonic is 'a' .addLabel(condition, "Save &as:") .xy(1, 1) // Mnemonic is the second 'a' .addLabel(condition, "Look&&Feel:").xy(1, 1) // No mnemonic, text is "look&feel" ... .build();
expression
- the precondition for adding the labelmarkedText
- the label's text -
may contain an ampersand (&) to mark a mnemonic,
and it may be a format stringargs
- optional format argumentsMnemonicUtils
,
ComponentFactory
,
String.format(String, Object...)
public FormBuilder.ComponentAdder addROLabel(boolean expression, String markedText, Object... args)
The read-only labels created by the default component factory are slightly lighter than plain labels. This makes it easier to differ between the labeling text and the text value that is labeled.
return FormBuilder.create() ... .addROLabel(condition, "Name:") .xy(1, 1) // No Mnemonic .addROLabel(condition, "N&ame:") .xy(1, 1) // Mnemonic is 'a' .addROLabel(condition, "Save &as:") .xy(1, 1) // Mnemonic is the second 'a' .addROLabel(condition, "Look&&Feel:").xy(1, 1) // No mnemonic, text is "look&feel" ... .build();
expression
- the precondition for adding the read-only labelmarkedText
- the label's text -
may contain an ampersand (&) to mark a mnemonic,
and it may be a format stringargs
- optional format argumentsMnemonicUtils
,
ComponentFactory
,
String.format(String, Object...)
public FormBuilder.ComponentAdder addTitle(boolean expression, String markedText, Object... args)
return FormBuilder.create() ... .addTitle(condition, "Name") .xy(1, 1) // No mnemonic .addTitle(condition, "N&ame") .xy(1, 1) // Mnemonic is 'a' .addTitle(condition, "Look&&Feel").xy(1, 1) // No mnemonic, text is Look&Feel ... .build();
expression
- the precondition for adding the titlemarkedText
- the title label's text -
may contain an ampersand (&) to mark a mnemonic,
and it may be a format stringargs
- optional format argumentsMnemonicUtils
,
ComponentFactory
,
String.format(String, Object...)
public FormBuilder.ComponentAdder addSeparator(boolean expression, String markedText, Object... args)
return FormBuilder.create() ... .addSeparator(condition, "Name") .xyw(1, 1, 3) // No Mnemonic .addSeparator(condition, "N&ame") .xyw(1, 1, 3) // Mnemonic is 'a' .addSeparator(condition, "Look&&Feel").xyw(1, 1, 3) // No mnemonic, text is "look&feel" ... .build();
expression
- the precondition for adding the separatormarkedText
- the separator label's text -
may contain an ampersand (&) to mark a mnemonic,
and it may be a format stringargs
- optional format argumentsMnemonicUtils
,
ComponentFactory
,
String.format(String, Object...)
public FormBuilder.ComponentAdder add(boolean expression, Icon image)
image
is null, nothing will be added.expression
- the precondition for adding the iconimage
- the image to be displayed by the added labelJLabel.JLabel(Icon)
protected LayoutMap getLayoutMap()
protected FormLayout getLayout()
protected ComponentFactory getFactory()
protected FormBuilder.ComponentAdder addImpl(Component c)
Copyright © 2002-2015 JGoodies Software GmbH. All Rights Reserved.