Package ca.corbett.forms.fields
Class FontField
java.lang.Object
ca.corbett.forms.fields.FormField
ca.corbett.forms.fields.FontField
A FormField implementation that provides the ability to select a Font, with
optional abilities to select font size, font color, and font background color.
This form field presents options for choosing a font from any of the installed
fonts on the system, or by using the built-in Java Font abstraction names,
like "SansSerif" or "Monospaced", which will map to some system-installed font.
See also FontDialog, which is used by this FormField but which can also
be used standalone if you need to select a Font.
- Since:
- 2025-04-07
- Author:
- scorbo2
-
Field Summary
Fields inherited from class ca.corbett.forms.fields.FormField
DEFAULT_FONT, defaultFont, extraAttributes, fieldComponent, fieldLabel, fieldValidators, helpLabel, identifier, isEnabled, isVisible, margins, validationLabel, valueChangedListeners -
Constructor Summary
ConstructorsConstructorDescriptionCreates a FontField with the given label text and default initial settings.Creates a FontField with the given label text and the given initial Font.Creates a FontField with the given label text and the given initial Font, and allows changing the text color but not the background color.Creates a FontField with the given label text and the given initial Font, and allows changing both the text color and the background color. -
Method Summary
Modifier and TypeMethodDescriptionIf background color modification is allowed, returns the selected text color, otherwise null.Returns the Font selected by the user, or the default Font if the user did not make a selection.If text color modification is allowed, returns the selected text color, otherwise null.booleanReports whether or not the size chooser is visible in this field.voidInvoke before rendering this FormField to a container, in case the FormField needs to do some initialization specific to its new container (for example, matching the container's background color or using the container as a parent component for a popup dialog).setBgColor(Color bgColor) Sets the selected background color, if bg color is editable in this field, otherwise does nothing.voidsetEnabled(boolean enabled) Enables or disables all components in this field.setSelectedFont(Font font) Sets the selected Font.voidsetShowSizeField(boolean show) Controls the visibility of the size chooser on the popup font chooser dialog.setTextColor(Color textColor) Sets the selected text color, if text color is editable in this field, otherwise does nothing.Methods inherited from class ca.corbett.forms.fields.FormField
addAllExtraAttributes, addFieldValidator, addValueChangedListener, clearExtraAttribute, clearExtraAttributes, clearValidationResults, equals, fireValueChangedEvent, getDefaultFont, getExtraAttribute, getFieldComponent, getFieldLabel, getHelpLabel, getHelpText, getIdentifier, getMargins, getValidationLabel, hasFieldLabel, hashCode, hasHelpLabel, hasValidationLabel, isEnabled, isMultiLine, isValid, isVisible, removeAllFieldValidators, removeFieldValidator, removeValueChangedListener, setAllExtraAttributes, setDefaultFont, setExtraAttribute, setFieldLabelFont, setHelpText, setIdentifier, setMargins, setVisible, shouldExpand, validate
-
Constructor Details
-
FontField
Creates a FontField with the given label text and default initial settings. Text color and background color will not be editable.- Parameters:
labelText- The text to show for the field label.
-
FontField
Creates a FontField with the given label text and the given initial Font. Text color and background color will not be editable.- Parameters:
labelText- The text to show for the field label.initialFont- The Font to set for the initial value.
-
FontField
Creates a FontField with the given label text and the given initial Font, and allows changing the text color but not the background color.- Parameters:
labelText- The text to show for the field label.initialFont- The Font to set for the initial value.textColor- The initial text color to set.
-
FontField
Creates a FontField with the given label text and the given initial Font, and allows changing both the text color and the background color.- Parameters:
labelText- The text to show for the field label.initialFont- The Font to set for the initial value.textColor- The initial text color to set.bgColor- The initial background color to set.
-
-
Method Details
-
setShowSizeField
public void setShowSizeField(boolean show) Controls the visibility of the size chooser on the popup font chooser dialog. This must be set before the field is rendered. Some use cases require choosing just the font and not also the size. -
isShowSizeField
public boolean isShowSizeField()Reports whether or not the size chooser is visible in this field. -
getSelectedFont
Returns the Font selected by the user, or the default Font if the user did not make a selection.- Returns:
- The selected Font.
-
setSelectedFont
Sets the selected Font. Overwrites whatever the user has chosen before now.- Parameters:
font- The Font to select.
-
getTextColor
If text color modification is allowed, returns the selected text color, otherwise null.- Returns:
- A text color, or null if color editing not enabled.
-
setTextColor
Sets the selected text color, if text color is editable in this field, otherwise does nothing.- Parameters:
textColor- The new text color (overrides any previous selection).
-
getBgColor
If background color modification is allowed, returns the selected text color, otherwise null.- Returns:
- A text color, or null if color editing not enabled.
-
setBgColor
Sets the selected background color, if bg color is editable in this field, otherwise does nothing.- Parameters:
bgColor- The new background color (overrides any previous selection).
-
setEnabled
public void setEnabled(boolean enabled) Description copied from class:FormFieldEnables or disables all components in this field.- Overrides:
setEnabledin classFormField- Parameters:
enabled- whether to enable or disable the components.
-
preRender
Description copied from class:FormFieldInvoke before rendering this FormField to a container, in case the FormField needs to do some initialization specific to its new container (for example, matching the container's background color or using the container as a parent component for a popup dialog). The default implementation here does nothing. Overriding this method is optional.
-