Class HTMLLabel

All Implemented Interfaces:
Styleable, EventTarget

public class HTMLLabel extends TextFlow
A lightweight HTML label that mimics Swing's JLabel for basic HTML formatting. Supports <html>, <b>, <i> and <br> tags.

This control does not load fonts itself. Bold and italic styles are resolved through the application-wide FontRegistry, which must be populated once during application startup for every loaded font file (e.g. Inter-Bold.ttf, Inter-Italic.ttf). If no registered style is found, the label falls back to JavaFX's built-in font factory.

  • Property Details

  • Constructor Details

    • HTMLLabel

      public HTMLLabel()
      Creates an empty HTML label.
    • HTMLLabel

      public HTMLLabel(String html)
      Creates an HTML label with the specified initial content.
      Parameters:
      html - the initial HTML content to display
  • Method Details

    • layoutChildren

      protected void layoutChildren()
      Overrides:
      layoutChildren in class TextFlow
    • fontProperty

      public final ObjectProperty<Font> fontProperty()
      Returns the font property used by this label.
      Returns:
      the font property
      See Also:
    • setFont

      public final void setFont(Font font)
      Sets the base font used to render the label text.
      Parameters:
      font - the font to use, or null to use the default font
    • getFont

      public final Font getFont()
      Returns the base font used to render the label text.
      Returns:
      the current font
    • textProperty

      public final StringProperty textProperty()
      Returns the text property for FXML compatibility.
      Returns:
      the text property
      See Also:
    • setText

      public final void setText(String text)
      Sets the label content, interpreting HTML when the text starts with an <html> tag. Otherwise, displays the content as plain text.
      Parameters:
      text - the text or HTML content to display, or null to clear the label
    • getText

      public final String getText()
      Returns the text or HTML content displayed by this label.
      Returns:
      the current text or HTML content
    • setHtml

      public void setHtml(String html)
      Sets the label content as HTML.
      Parameters:
      html - the HTML content to display, or null to clear the label