Package swingtree

Class UI.Font

java.lang.Object
java.awt.Font
swingtree.UI.Font
All Implemented Interfaces:
Serializable
Enclosing class:
UI

public static final class UI.Font extends Font
This class represents a SwingTree font and is used to specify the font of a component. It is a subclass of Font and provides additional functionality. The appearance of a font is primarily based on the font family name which is used to find a font on the system.
See Also:
  • Field Details

    • UNDEFINED

      public static final Font UNDEFINED
      This constant is a Font object with a font name of "" (empty string), a font style of -1 (undefined) and a font size of 0. Its identity is used to represent the absence of a font being specified, and it is used as a safe replacement for null, meaning that when the style engine of a component encounters it, it will pass it onto the Component.setFont(java.awt.Font) method as null. Passing null to this method means that the look and feel determines the font.
  • Method Details

    • of

      public static UI.Font of(String name, UI.FontStyle style, int size)
      A factory method that creates a new Font object with the specified font name UI.FontStyle and size. This maps directly to the constructor of Font(String, int, int).
      Parameters:
      name - The font name, which may be anything depending on what fonts are loaded on the system.
      style - The style of the font, which is one of the constants UI.FontStyle.PLAIN,
      size - The point size of the font.
      Returns:
      A new Font object with the specified font name, style and size.
    • of

      public static UI.Font of(Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
      Creates a new Font object from a map of attributes where the key is an attribute and the value is the value of the attribute. See TextAttribute for a list of common attributes. These attributes define the style of the font.
      Parameters:
      attributes - A map of attributes that define the style of the font.
      Returns:
      A new Font object with the specified attributes.
    • of

      public static UI.Font of(Font font)
      Creates a new UI.Font object from a Font object.
      Parameters:
      font - The font to convert to a font.
      Returns:
      The SwingTree native font object.
    • withName

      public UI.Font withName(String name)
      Returns an updated version of this font with the font (family) name changed to the specified value.
      Parameters:
      name - The font name, which may be anything depending on what fonts are loaded on the system.
      Returns:
      A new Font object with the font name changed.
      Throws:
      NullPointerException - If the font name is null.
    • withStyle

      public UI.Font withStyle(UI.FontStyle style)
      Returns an updated version of this font with the font style changed to the specified value.
      Parameters:
      style - The style of the font, which is one of the constants UI.FontStyle.PLAIN, UI.FontStyle.BOLD or UI.FontStyle.ITALIC.
      Returns:
      A new Font object with the font style changed.
    • withSize

      public UI.Font withSize(int size)
      Returns an updated version of this font with the font size changed to the specified value.
      Parameters:
      size - The point size of the font.
      Returns:
      A new Font object with the font size changed.