Class FontComboUtil

java.lang.Object
jmri.util.swing.FontComboUtil

public class FontComboUtil extends Object
This utility class provides methods that initialise and return a JComboBox containing a specific sub-set of fonts installed on a users system.

Optionally, the JComboBox can be displayed with a preview of the specific font in the drop-down list itself.


This file is part of JMRI.

JMRI is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. See the "COPYING" file for a copy of this license.

JMRI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Since:
2.13.1
  • Field Details

  • Constructor Details

  • Method Details

    • getFonts

      public static List<String> getFonts(int which)
    • isSymbolFont

      public static boolean isSymbolFont(String font)
      Determine if the specified font family is a symbol font
      Parameters:
      font - the font family to check
      Returns:
      true if a symbol font; false if not
    • prepareFontLists

      public static void prepareFontLists()
      Method to initialise the font lists on first access
    • getFontCombo

      public static JComboBox<String> getFontCombo()
      Return a JComboBox containing all available font families. The list is displayed using a preview of the font at the standard size.
      Returns:
      List of all available font families as a JComboBox
      See Also:
    • getFontCombo

      public static JComboBox<String> getFontCombo(boolean previewOnly)
      Return a JComboBox containing all available font families. The list is displayed using a preview of the font at the standard size and with the option of the name alongside in the regular dialog font.
      Parameters:
      previewOnly - set to True to show only a preview in the list; False to show both name and preview
      Returns:
      List of specified font families as a JComboBox
      See Also:
    • getFontCombo

      public static JComboBox<String> getFontCombo(int which)
      Return a JComboBox containing the specified set of font families. The list is displayed using a preview of the font at the standard size.
      Parameters:
      which - the set of fonts to return; MONOSPACED, PROPORTIONAL, CHARACTER, SYMBOL or ALL
      Returns:
      List of specified font families as a JComboBox
      See Also:
    • getFontCombo

      public static JComboBox<String> getFontCombo(int which, boolean previewOnly)
      Return a JComboBox containing the specified set of font families. The list is displayed using a preview of the font at the standard size and with the option of the name alongside in the regular dialog font.
      Parameters:
      which - the set of fonts to return; MONOSPACED, PROPORTIONAL, CHARACTER, SYMBOL or ALL
      previewOnly - set to True to show only a preview in the list; False to show both name and preview
      Returns:
      List of specified font families as a JComboBox
      See Also:
    • getFontCombo

      public static JComboBox<String> getFontCombo(int which, int size)
      Return a JComboBox containing the specified set of font families. The list is displayed using a preview of the font at the specified point size.
      Parameters:
      which - the set of fonts to return; MONOSPACED, PROPORTIONAL, CHARACTER, SYMBOL or ALL
      size - point size for the preview
      Returns:
      List of specified font families as a JComboBox
      See Also:
    • getFontCombo

      public static JComboBox<String> getFontCombo(int which, int size, boolean previewOnly)
      Return a JComboBox containing the specified set of font families. The list is displayed using a preview of the font at the specified point size and with the option of the name alongside in the regular dialog font.

      Available font sets:

      Typical usage:

       JComboBox fontFamily = FontComboUtil.getFontCombo(FontComboUtil.MONOSPACED);
       fontFamily.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                myObject.setFontFamily((String) ((JComboBox)e.getSource()).getSelectedItem());
            }
        });
        fontFamily.setSelectedItem(myObject.getFontFamily());
       
      Parameters:
      which - the set of fonts to return; MONOSPACED, PROPORTIONAL, CHARACTER, SYMBOL or ALL
      size - point size for the preview
      previewOnly - true to show only a preview in the list; false to show both name and preview
      Returns:
      List of specified font families as a JComboBox
    • isReady

      public static boolean isReady()
      Determine if usable; starts the process of making it so if needed
      Returns:
      true if ready for use; false otherwise