com.jgoodies.forms.factories
public class DefaultComponentFactory extends java.lang.Object implements ComponentFactory2
ComponentFactory
interface
that creates UI components as required by the
PanelBuilder
.
The texts used in methods #createLabel(String)
and
#createTitle(String)
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".
Constructor and Description |
---|
DefaultComponentFactory() |
Modifier and Type | Method and Description |
---|---|
javax.swing.JLabel |
createLabel(java.lang.String textWithMnemonic)
Creates and returns a label with an optional mnemonic.
|
javax.swing.JLabel |
createReadOnlyLabel(java.lang.String textWithMnemonic)
Creates and returns a label with an optional mnemonic
that is intended to label a read-only component.
|
javax.swing.JComponent |
createSeparator(javax.swing.JLabel label)
Creates and returns a labeled separator.
|
javax.swing.JComponent |
createSeparator(java.lang.String textWithMnemonic)
Creates and returns a labeled separator with the label in the left-hand
side.
|
javax.swing.JComponent |
createSeparator(java.lang.String textWithMnemonic,
int alignment)
Creates and returns a labeled separator.
|
javax.swing.JLabel |
createTitle(java.lang.String textWithMnemonic)
Creates and returns a title label that uses the foreground color
and font of a
TitledBorder . |
static DefaultComponentFactory |
getInstance()
Returns the sole instance of this factory class.
|
static void |
setTextAndMnemonic(javax.swing.JLabel label,
java.lang.String textWithMnemonic)
Sets the text of the given label and optionally a mnemonic.
|
public static DefaultComponentFactory getInstance()
public javax.swing.JLabel createLabel(java.lang.String textWithMnemonic)
createLabel("Name"); // No mnemonic createLabel("N&ame"); // Mnemonic is 'a' createLabel("Save &as"); // Mnemonic is the second 'a' createLabel("Look&&Feel"); // No mnemonic, text is Look&Feel
createLabel
in interface ComponentFactory
textWithMnemonic
- the label's text -
may contain an ampersand (&) to mark a mnemonicpublic javax.swing.JLabel createReadOnlyLabel(java.lang.String textWithMnemonic)
createReadOnlyLabel("Name"); // No mnemonic createReadOnlyLabel("N&ame"); // Mnemonic is 'a' createReadOnlyLabel("Save &as"); // Mnemonic is the second 'a' createReadOnlyLabel("Look&&Feel"); // No mnemonic, text is Look&Feel
createReadOnlyLabel
in interface ComponentFactory2
textWithMnemonic
- the label's text -
may contain an ampersand (&) to mark a mnemonicComponentFactory2
public javax.swing.JLabel createTitle(java.lang.String textWithMnemonic)
TitledBorder
.
createTitle("Name"); // No mnemonic createTitle("N&ame"); // Mnemonic is 'a' createTitle("Save &as"); // Mnemonic is the second 'a' createTitle("Look&&Feel"); // No mnemonic, text is Look&Feel
createTitle
in interface ComponentFactory
textWithMnemonic
- the label's text -
may contain an ampersand (&) to mark a mnemonicpublic javax.swing.JComponent createSeparator(java.lang.String textWithMnemonic)
TitledBorder
.
createSeparator("Name"); // No mnemonic createSeparator("N&ame"); // Mnemonic is 'a' createSeparator("Save &as"); // Mnemonic is the second 'a' createSeparator("Look&&Feel"); // No mnemonic, text is Look&Feel
textWithMnemonic
- the label's text -
may contain an ampersand (&) to mark a mnemonicpublic javax.swing.JComponent createSeparator(java.lang.String textWithMnemonic, int alignment)
TitledBorder
.
final int LEFT = SwingConstants.LEFT; createSeparator("Name", LEFT); // No mnemonic createSeparator("N&ame", LEFT); // Mnemonic is 'a' createSeparator("Save &as", LEFT); // Mnemonic is the second 'a' createSeparator("Look&&Feel", LEFT); // No mnemonic, text is Look&Feel
createSeparator
in interface ComponentFactory
textWithMnemonic
- the label's text -
may contain an ampersand (&) to mark a mnemonicalignment
- text alignment, one of SwingConstants.LEFT
,
SwingConstants.CENTER
, SwingConstants.RIGHT
public javax.swing.JComponent createSeparator(javax.swing.JLabel label)
TitledBorder
.
The label's position is determined by the label's horizontal alignment,
which must be one of:
SwingConstants.LEFT
,
SwingConstants.CENTER
,
SwingConstants.RIGHT
.
TODO: Since this method has been marked public in version 1.0.6, we need to precisely describe the semantic of this method.
TODO: Check if we can relax the constraint for the label alignment and also accept LEADING and TRAILING.
label
- the title label componentjava.lang.NullPointerException
- if the label is null
java.lang.IllegalArgumentException
- if the label's horizontal alignment
is not one of: SwingConstants.LEFT
,
SwingConstants.CENTER
,
SwingConstants.RIGHT
.public static void setTextAndMnemonic(javax.swing.JLabel label, java.lang.String textWithMnemonic)
label
- the label that gets a mnemonictextWithMnemonic
- the text with optional mnemonic markerCopyright © 2002-2009 JGoodies Karsten Lentzsch. All Rights Reserved.