Class DefaultComponentFactory
- All Implemented Interfaces:
ComponentFactory
ComponentFactory
interface
that creates UI components as required by the
FormBuilder
, ListViewBuilder
, and other builders.
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".
- Version:
- $Revision: 1.21 $
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Differs from its superclass JLabel in that it removes a trailing colon (':') - if any - from the label's accessible name.private static final class
A FormsLabel subclasses intended to label read-only components.private static final class
A layout for the title label and separator(s) in titled separators.private static final class
A label that uses the TitleBorder font and color. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final DefaultComponentFactory
Holds the single instance of this class. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateButton
(Action action) Creates and returns a button that is bound to the given Action.createHeaderLabel
(String markedText) Creates and returns a label intended for pane headers that uses a larger font than the control font and a special foreground color.createLabel
(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.
-
Field Details
-
INSTANCE
Holds the single instance of this class.
-
-
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("N&ame"); // Mnemonic is 'a' createLabel("Save &as"); // Mnemonic is the second 'a' createLabel("Look&&Feel"); // No mnemonic, text is Look&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("N&ame"); // Mnemonic is 'a' createReadOnlyLabel("Save &as"); // Mnemonic is the second 'a' createReadOnlyLabel("Look&&Feel"); // No mnemonic, text is Look&Feel
- Specified by:
createReadOnlyLabel
in interfaceComponentFactory
- 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
-
createButton
Creates and returns a button that is bound to the given Action. Useful to return customized buttons, for example, the JGoodiesJGButton
is bound to some custom Action properties.This default implementation just returns a
JButton
.- Specified by:
createButton
in interfaceComponentFactory
- Parameters:
action
- provides [bound] visual properties for the button- Returns:
- the created button
- Since:
- 1.4
-
createTitle
Creates and returns a title label that uses the foreground color and font of aTitledBorder
.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
- Specified by:
createTitle
in interfaceComponentFactory
- Parameters:
textWithMnemonic
- the label's text - may contain an ampersand (&) to mark a mnemonic- Returns:
- an emphasized title label
-
createHeaderLabel
Description copied from interface:ComponentFactory
Creates and returns a label intended for pane headers that uses a larger font than the control font and a special foreground color. For example, on the Windows platform this method may use the font, size, and color of the TaskDialog main instruction as described by the MS User Experience Guide.If the label text is marked with the mnemonic marker '&', the mnemonic and mnemonic index will be configured. For example if
markedText
is "&Charge Codes", the text will be set to "Charge Codes", the mnemonic is 'C', and the mnemonic index is 0.A simple implementation may just delegate to
ComponentFactory.createTitle(String)
.- Specified by:
createHeaderLabel
in interfaceComponentFactory
- Parameters:
markedText
- the label text with optional mnemonic marker- Returns:
- a label intended for pane headers
-
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("N&ame"); // Mnemonic is 'a' createSeparator("Save &as"); // Mnemonic is the second 'a' createSeparator("Look&&Feel"); // No mnemonic, text is Look&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("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
- 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
-