Class GlyphFont

java.lang.Object
org.controlsfx.glyphfont.GlyphFont
Direct Known Subclasses:
FontAwesome

public class GlyphFont extends Object
Represents a glyph font, which can be loaded locally or from a specified URL. Glyphs can be created easily using specified character defined in the font. For example, \uf013 in FontAwesome is used to represent a gear icon.

To simplify glyph customization, methods can be chained, for example:

  Glyph glyph = fontAwesome.create('\uf013').size(28).color(Color.RED); //GEAR
  

Here's a screenshot of two font packs being used to render images into JavaFX Button controls:

Screenshot of GlyphFont
  • Constructor Details

    • GlyphFont

      public GlyphFont(String fontName, int defaultSize, InputStream in)
      Loads glyph font from specified InputStream
      Parameters:
      fontName - glyph font name
      defaultSize - default font size
      in - input stream to load the font from
    • GlyphFont

      public GlyphFont(String fontName, int defaultSize, String urlStr)
      Load glyph font from specified URL. Example for a local file: "file:///C:/Users/Bob/Fonts/icomoon.ttf" "file:///Users/Bob/Fonts/icomoon.ttf"
      Parameters:
      fontName - glyph font name
      defaultSize - default font size
      urlStr - A URL to load the font from
    • GlyphFont

      public GlyphFont(String fontName, int defaultSize, InputStream in, boolean lazyLoad)
      Loads glyph font from specified InputStream
      Parameters:
      fontName - glyph font name
      defaultSize - default font size
      in - input stream to load the font from
      lazyLoad - If true, the font will only be loaded when accessed
    • GlyphFont

      public GlyphFont(String fontName, int defaultSize, String urlStr, boolean lazyLoad)
      Load glyph font from specified URL. Example for a local file: "file:///C:/Users/Bob/Fonts/icomoon.ttf" "file:///Users/Bob/Fonts/icomoon.ttf"
      Parameters:
      fontName - glyph font name
      defaultSize - default font size
      urlStr - A URL to load the font from
      lazyLoad - If true, the font will only be loaded when accessed
  • Method Details

    • getName

      public String getName()
      Returns font name
      Returns:
      font name
    • getDefaultSize

      public double getDefaultSize()
      Returns the default font size
      Returns:
      default font size
    • create

      public Glyph create(char character)
      Creates an instance of Glyph using specified font character
      Parameters:
      character - font character
      Returns:
      instance of Glyph
    • create

      public Glyph create(String glyphName)
      Creates an instance of Glyph using glyph name
      Parameters:
      glyphName - glyph name
      Returns:
      glyph by its name or null if name is not found
    • create

      public Glyph create(Enum<?> glyph)
      Creates an instance of Glyph using a known Glyph enum value
      Parameters:
      glyph -
    • getCharacter

      public Character getCharacter(String glyphName)
      Returns the character code which is mapped to this Name. If no match is found, NULL is returned.
      Parameters:
      glyphName -
    • registerAll

      public void registerAll(Iterable<? extends INamedCharacter> namedCharacters)
      Registers all given characters with their name.
      Parameters:
      namedCharacters -
    • register

      public void register(String name, Character character)
      Registers the given name-character mapping
      Parameters:
      name -
      character -