Class FontField

java.lang.Object
ca.corbett.forms.fields.FormField
ca.corbett.forms.fields.FontField

public final class FontField extends FormField
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
  • Constructor Details

    • FontField

      public FontField(String labelText)
      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

      public FontField(String labelText, Font initialFont)
      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

      public FontField(String labelText, Font initialFont, Color textColor)
      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

      public FontField(String labelText, Font initialFont, Color textColor, Color bgColor)
      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

      public Font 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

      public FontField setSelectedFont(Font font)
      Sets the selected Font. Overwrites whatever the user has chosen before now.
      Parameters:
      font - The Font to select.
    • getTextColor

      public Color 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

      public FontField setTextColor(Color textColor)
      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

      public Color 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

      public FontField setBgColor(Color bgColor)
      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: FormField
      Enables or disables all components in this field.
      Overrides:
      setEnabled in class FormField
      Parameters:
      enabled - whether to enable or disable the components.
    • preRender

      public void preRender(JPanel container)
      Description copied from class: FormField
      Invoke 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.
      Overrides:
      preRender in class FormField