Package smile.swing

Class FontChooser

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class FontChooser extends JComponent
The FontChooser class is a swing component for font selection with JFileChooser-like APIs. The following code pops up a font chooser dialog.
 
   FontChooser fontChooser = FontChooser.getInstance();
   int result = fontChooser.showDialog(parent);
   if (result == FontChooser.OK_OPTION) {
       Font font = fontChooser.getSelectedFont();
   }
 
 
See Also:
  • Field Details

  • Constructor Details

    • FontChooser

      public FontChooser()
      Constructs a FontChooser object.
    • FontChooser

      public FontChooser(String[] fontSizeStrings)
      Constructs a FontChooser object using the given font size array.
      Parameters:
      fontSizeStrings - the array of font size string.
  • Method Details

    • getMessage

      protected String getMessage(String key)
    • getInstance

      public static FontChooser getInstance()
      Returns the shared font chooser instance. In general, an application should have only one font chooser so that it always knows the latest chosen font.
    • getSelectedFontFamily

      public String getSelectedFontFamily()
      Get the family name of the selected font.
      Returns:
      the font family of the selected font.
      See Also:
    • getSelectedFontStyle

      public int getSelectedFontStyle()
      Get the style of the selected font.
      Returns:
      the style of the selected font. Font.PLAIN, Font.BOLD, Font.ITALIC, Font.BOLD|Font.ITALIC
      See Also:
    • getSelectedFontSize

      public int getSelectedFontSize()
      Get the size of the selected font.
      Returns:
      the size of the selected font
      See Also:
    • getSelectedFont

      public Font getSelectedFont()
      Get the selected font.
      Returns:
      the selected font
      See Also:
    • setSelectedFontFamily

      public FontChooser setSelectedFontFamily(String name)
      Set the family name of the selected font.
      Parameters:
      name - the family name of the selected font.
      See Also:
    • setSelectedFontStyle

      public FontChooser setSelectedFontStyle(int style)
      Set the style of the selected font.
      Parameters:
      style - the size of the selected font. Font.PLAIN, Font.BOLD, Font.ITALIC, or Font.BOLD|Font.ITALIC.
      See Also:
    • setSelectedFontSize

      public FontChooser setSelectedFontSize(int size)
      Set the size of the selected font.
      Parameters:
      size - the size of the selected font
      See Also:
    • setSelectedFont

      public FontChooser setSelectedFont(Font font)
      Set the selected font.
      Parameters:
      font - the selected font
      See Also:
    • showDialog

      public int showDialog(Component parent)
      Show font selection dialog.
      Parameters:
      parent - Dialog's Parent component.
      Returns:
      OK_OPTION, CANCEL_OPTION or ERROR_OPTION
      See Also: