Class DefaultComponentFactory
- All Implemented Interfaces:
ComponentFactory
,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 "&Saveinvalid input: '"',
or "Save &asinvalid input: '"'. To use the ampersand itself
duplicate it, for example "Look&&Feelinvalid input: '"'.
- Version:
- $Revision: 1.16 $
- Author:
- Karsten Lentzsch
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateLabel
(String textWithMnemonic) Creates and returns a label with an optional mnemonic.createReadOnlyLabel
(String textWithMnemonic) Creates and returns a label with an optional mnemonic that is intended to label a read-only component.createSeparator
(String textWithMnemonic) Creates and returns a labeled separator with the label in the left-hand side.createSeparator
(String textWithMnemonic, int alignment) Creates and returns a labeled separator.createSeparator
(JLabel label) Creates and returns a labeled separator.createTitle
(String textWithMnemonic) Creates and returns a title label that uses the foreground color and font of aTitledBorder
.static DefaultComponentFactory
Returns the sole instance of this factory class.static void
setTextAndMnemonic
(JLabel label, String textWithMnemonic) Sets the text of the given label and optionally a mnemonic.
-
Constructor Details
-
DefaultComponentFactory
public DefaultComponentFactory()
-
-
Method Details
-
getInstance
Returns the sole instance of this factory class.- Returns:
- the sole instance of this factory class
-
createLabel
Creates and returns a label with an optional mnemonic.createLabel("Name"); // No mnemonic createLabel("Ninvalid input: '&ame'"); // Mnemonic is 'a' createLabel("Save invalid input: '&as'"); // Mnemonic is the second 'a' createLabel("Lookinvalid input: '&'invalid input: '&Feel'"); // No mnemonic, text is Lookinvalid input: '&Feel'
- Specified by:
createLabel
in interfaceComponentFactory
- Parameters:
textWithMnemonic
- the label's text - may contain an ampersand (&) to mark a mnemonic- Returns:
- an label with optional mnemonic
-
createReadOnlyLabel
Creates and returns a label with an optional mnemonic that is intended to label a read-only component.createReadOnlyLabel("Name"); // No mnemonic createReadOnlyLabel("Ninvalid input: '&ame'"); // Mnemonic is 'a' createReadOnlyLabel("Save invalid input: '&as'"); // Mnemonic is the second 'a' createReadOnlyLabel("Lookinvalid input: '&'invalid input: '&Feel'"); // No mnemonic, text is Lookinvalid input: '&Feel'
- Specified by:
createReadOnlyLabel
in interfaceComponentFactory2
- Parameters:
textWithMnemonic
- the label's text - may contain an ampersand (&) to mark a mnemonic- Returns:
- an label with optional mnemonic intended for read-only components
- Since:
- 1.3
- See Also:
-
createTitle
Creates and returns a title label that uses the foreground color and font of aTitledBorder
.createTitle("Name"); // No mnemonic createTitle("Ninvalid input: '&ame'"); // Mnemonic is 'a' createTitle("Save invalid input: '&as'"); // Mnemonic is the second 'a' createTitle("Lookinvalid input: '&'invalid input: '&Feel'"); // No mnemonic, text is Lookinvalid input: '&Feel'
- Specified by:
createTitle
in interfaceComponentFactory
- Parameters:
textWithMnemonic
- the label's text - may contain an ampersand (&) to mark a mnemonic- Returns:
- an emphasized title label
-
createSeparator
Creates and returns a labeled separator with the label in the left-hand side. Useful to separate paragraphs in a panel; often a better choice than aTitledBorder
.createSeparator("Name"); // No mnemonic createSeparator("Ninvalid input: '&ame'"); // Mnemonic is 'a' createSeparator("Save invalid input: '&as'"); // Mnemonic is the second 'a' createSeparator("Lookinvalid input: '&'invalid input: '&Feel'"); // No mnemonic, text is Lookinvalid input: '&Feel'
- Parameters:
textWithMnemonic
- the label's text - may contain an ampersand (&) to mark a mnemonic- Returns:
- a title label with separator on the side
-
createSeparator
Creates and returns a labeled separator. Useful to separate paragraphs in a panel, which is often a better choice than aTitledBorder
.final int LEFT = SwingConstants.LEFT; createSeparator("Name", LEFT); // No mnemonic createSeparator("Ninvalid input: '&ame'", LEFT); // Mnemonic is 'a' createSeparator("Save invalid input: '&as'", LEFT); // Mnemonic is the second 'a' createSeparator("Lookinvalid input: '&'invalid input: '&Feel'", LEFT); // No mnemonic, text is Lookinvalid input: '&Feel'
- Specified by:
createSeparator
in interfaceComponentFactory
- Parameters:
textWithMnemonic
- the label's text - may contain an ampersand (&) to mark a mnemonicalignment
- text alignment, one ofSwingConstants.LEFT
,SwingConstants.CENTER
,SwingConstants.RIGHT
- Returns:
- a separator with title label
-
createSeparator
Creates and returns a labeled separator. Useful to separate paragraphs in a panel, which is often a better choice than aTitledBorder
.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.
- Parameters:
label
- the title label component- Returns:
- a separator with title label
- Throws:
NullPointerException
- if the label isnull
IllegalArgumentException
- if the label's horizontal alignment is not one of:SwingConstants.LEFT
,SwingConstants.CENTER
,SwingConstants.RIGHT
.- Since:
- 1.0.6
-
setTextAndMnemonic
Sets the text of the given label and optionally a mnemonic. The given text may contain an ampersand (&) to mark a mnemonic and its position. Such a marker indicates that the character that follows the ampersand shall be the mnemonic. If you want to use the ampersand itself duplicate it, for example "Look&&Feelinvalid input: '"'.- Parameters:
label
- the label that gets a mnemonictextWithMnemonic
- the text with optional mnemonic marker- Since:
- 1.2
-