Class FontDialog

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public final class FontDialog extends JDialog
Represents a dialog that can be shown to the user to allow selection of a font with style properties and optional foreground/background color selection. This dialog was written for and is used by the FontField, but you could also invoke this dialog standalone if needed.
Since:
2025-04-07
Author:
scorbo2
See Also:
  • Field Details

    • INITIAL_FONT

      public static final Font INITIAL_FONT
  • Constructor Details

    • FontDialog

      public FontDialog(Component owner)
      Creates a new FontDialog with a default initial font and with foreground/background color selection disabled.
      Parameters:
      owner - The owning component (for dialog positioning purposes).
    • FontDialog

      public FontDialog(Component owner, Font initialFont)
      Creates a new FontDialog with the given initial font and with foreground/background color selection disabled.
      Parameters:
      owner - The owning component (for dialog positioning purposes).
    • FontDialog

      public FontDialog(Component owner, Font initialFont, Color textColor)
      Creates a new FontDialog with the given initial font and with foreground color selection enabled, but background color selection disabled.
      Parameters:
      owner - The owning component (for dialog positioning purposes).
    • FontDialog

      public FontDialog(Component owner, Font initialFont, Color textColor, Color bgColor)
      Creates a new FontDialog with the given initial font and with foreground and background color selection enabled.
      Parameters:
      owner - The owning component (for dialog positioning purposes).
  • Method Details

    • isShowSizeField

      public boolean isShowSizeField()
      Reports whether the size field is visible on this dialog. The size field is optional and the visibility can be set before the dialog is shown, with setSizeFieldVisible().
    • setShowSizeField

      public void setShowSizeField(boolean show)
      Toggles the visibility of the size chooser - this must be set before the dialog is shown. Some use cases require the setting of just the font face and style, without size.
    • wasOkayed

      public boolean wasOkayed()
      Reports whether the dialog was okayed by the user or not.
      Returns:
      True if the user hit OK, false if the dialog was closed any other way.
    • getSelectedFont

      public Font getSelectedFont()
      Returns the Font that was selected by the user, with style and size included.
      Returns:
      A Font object.
    • getSelectedTextColor

      public Color getSelectedTextColor()
      If foreground color editing was enabled in this dialog, will return the text foreground color that was selected by the user, otherwise null.
      Returns:
      A Color for text foreground, or null if foreground color editing disabled.
    • getSelectedBgColor

      public Color getSelectedBgColor()
      If background color editing was enabled in this dialog, will return the text background color that was selected by the user, otherwise null.
      Returns:
      A Color for text background, or null if background color editing disabled.