Class Label

All Implemented Interfaces:
Styleable, EventTarget, Skinnable

public class Label extends Labeled
Label is a non-editable text control. A Label is useful for displaying text that is required to fit within a specific space, and thus may need to use an ellipsis or truncation to size the string to fit. Labels also are useful in that they can have mnemonics which, if used, will send focus to the Control listed as the target of the labelFor property.

Label sets focusTraversable to false.

Example:

Label label = new Label("a label");
Image of the Label control
Since:
JavaFX 2.0
  • Property Details

  • Constructor Details

    • Label

      public Label()
      Creates an empty label
    • Label

      public Label(String text)
      Creates Label with supplied text.
      Parameters:
      text - null text is treated as the empty string
    • Label

      public Label(String text, Node graphic)
      Creates a Label with the supplied text and graphic.
      Parameters:
      text - null text is treated as the empty string
      graphic - a null graphic is acceptable
  • Method Details

    • labelForProperty

      public final ObjectProperty<Node> labelForProperty()
      A Label can act as a label for a different Control or Node. This is used for Mnemonics and Accelerator parsing. This allows setting of the target Node.
      Returns:
      the Node that this label is to be associated with
      See Also:
    • setLabelFor

      public final void setLabelFor(Node value)
      Sets the value of the labelFor property.
      Property description:
      A Label can act as a label for a different Control or Node. This is used for Mnemonics and Accelerator parsing. This allows setting of the target Node.
      Parameters:
      value - the value for the labelFor property
      See Also:
    • getLabelFor

      public final Node getLabelFor()
      Gets the value of the labelFor property.
      Property description:
      A Label can act as a label for a different Control or Node. This is used for Mnemonics and Accelerator parsing. This allows setting of the target Node.
      Returns:
      the value of the labelFor property
      See Also:
    • getInitialFocusTraversable

      protected Boolean getInitialFocusTraversable()
      Returns the initial focus traversable state of this control, for use by the JavaFX CSS engine to correctly set its initial value. This method is overridden as by default UI controls have focus traversable set to true, but that is not appropriate for this control.
      Overrides:
      getInitialFocusTraversable in class Control
      Returns:
      the initial focus traversable state of this control
      Since:
      9