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");
    Since:
    JavaFX 2.0
    • Property Detail

      • labelFor

        public 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.
        See Also:
        getLabelFor(), setLabelFor(Node)
    • Constructor Detail

      • 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 Detail

      • labelForProperty

        public 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.
        See Also:
        getLabelFor(), setLabelFor(Node)
      • setLabelFor

        public final void setLabelFor​(Node value)
        Sets the value of the property labelFor.
        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.
      • getLabelFor

        public final Node getLabelFor()
        Gets the value of the property labelFor.
        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.
      • createDefaultSkin

        protected Skin<?> createDefaultSkin()
        Create a new instance of the default skin for this control. This is called to create a skin for the control if no skin is provided via CSS -fx-skin or set explicitly in a sub-class with setSkin(...).
        Overrides:
        createDefaultSkin in class Control
        Returns:
        new instance of default skin for this control. If null then the control will have no skin unless one is provided by css.
      • 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