Class Labeled

All Implemented Interfaces:
Styleable, EventTarget, Skinnable
Direct Known Subclasses:
ButtonBase, Cell, Label, TitledPane

@DefaultProperty("text") public abstract class Labeled extends Control
A Labeled Control is one which has as part of its user interface a textual content associated with it. For example, a Button displays text, as does a Label, a Tooltip, and many other controls.

Labeled is also a convenient base class from which to extend when building new Controls which, as part of their UI, display read-only textual content.

Example of how to place a graphic above the text:


  Image image = new Image(getClass().getResourceAsStream("image.png"));
  ImageView imageView = new ImageView();
  imageView.setImage(image);
  Label label = new Label("text", imageView);
  label.setContentDisplay(ContentDisplay.TOP);
 
Since:
JavaFX 2.0
See Also:
  • Property Details

  • Constructor Details

    • Labeled

      public Labeled()
      Creates a Label with no text and graphic
    • Labeled

      public Labeled(String text)
      Creates a Label with text
      Parameters:
      text - The text for the label.
    • Labeled

      public Labeled(String text, Node graphic)
      Creates a Label with text and a graphic
      Parameters:
      text - The text for the label.
      graphic - The graphic for the label.
  • Method Details

    • textProperty

      public final StringProperty textProperty()
      The text to display in the label. The text may be null.
      Default value:
      empty string
      See Also:
    • setText

      public final void setText(String value)
      Sets the value of the property text.
      Property description:
      The text to display in the label. The text may be null.
      Default value:
      empty string
    • getText

      public final String getText()
      Gets the value of the property text.
      Property description:
      The text to display in the label. The text may be null.
      Default value:
      empty string
    • alignmentProperty

      public final ObjectProperty<Pos> alignmentProperty()
      Specifies how the text and graphic within the Labeled should be aligned when there is empty space within the Labeled.
      Default value:
      Pos.CENTER_LEFT
      See Also:
    • setAlignment

      public final void setAlignment(Pos value)
      Sets the value of the property alignment.
      Property description:
      Specifies how the text and graphic within the Labeled should be aligned when there is empty space within the Labeled.
      Default value:
      Pos.CENTER_LEFT
    • getAlignment

      public final Pos getAlignment()
      Gets the value of the property alignment.
      Property description:
      Specifies how the text and graphic within the Labeled should be aligned when there is empty space within the Labeled.
      Default value:
      Pos.CENTER_LEFT
    • textAlignmentProperty

      public final ObjectProperty<TextAlignment> textAlignmentProperty()
      Specifies the behavior for lines of text when text is multiline. Unlike contentDisplayProperty() which affects the graphic and text, this setting only affects multiple lines of text relative to the text bounds.
      Default value:
      TextAlignment.LEFT
      See Also:
    • setTextAlignment

      public final void setTextAlignment(TextAlignment value)
      Sets the value of the property textAlignment.
      Property description:
      Specifies the behavior for lines of text when text is multiline. Unlike contentDisplayProperty() which affects the graphic and text, this setting only affects multiple lines of text relative to the text bounds.
      Default value:
      TextAlignment.LEFT
    • getTextAlignment

      public final TextAlignment getTextAlignment()
      Gets the value of the property textAlignment.
      Property description:
      Specifies the behavior for lines of text when text is multiline. Unlike contentDisplayProperty() which affects the graphic and text, this setting only affects multiple lines of text relative to the text bounds.
      Default value:
      TextAlignment.LEFT
    • textOverrunProperty

      public final ObjectProperty<OverrunStyle> textOverrunProperty()
      Specifies the behavior to use if the text of the Labeled exceeds the available space for rendering the text.
      Default value:
      OverrunStyle.ELLIPSIS
      See Also:
    • setTextOverrun

      public final void setTextOverrun(OverrunStyle value)
      Sets the value of the property textOverrun.
      Property description:
      Specifies the behavior to use if the text of the Labeled exceeds the available space for rendering the text.
      Default value:
      OverrunStyle.ELLIPSIS
    • getTextOverrun

      public final OverrunStyle getTextOverrun()
      Gets the value of the property textOverrun.
      Property description:
      Specifies the behavior to use if the text of the Labeled exceeds the available space for rendering the text.
      Default value:
      OverrunStyle.ELLIPSIS
    • ellipsisStringProperty

      public final StringProperty ellipsisStringProperty()
      Specifies the string to display for the ellipsis when text is truncated.
      Ellipsis Table
      Examples
      "..." Default value for most locales
      " . . . "
      " [...] "
      "\u2026" The Unicode ellipsis character '…'
      "" No ellipsis, just display the truncated string

      Note that not all fonts support all Unicode characters.

      Default value:
      "..."
      Since:
      JavaFX 2.2
      See Also:
    • setEllipsisString

      public final void setEllipsisString(String value)
      Sets the value of the property ellipsisString.
      Property description:
      Specifies the string to display for the ellipsis when text is truncated.
      Ellipsis Table
      Examples
      "..." Default value for most locales
      " . . . "
      " [...] "
      "\u2026" The Unicode ellipsis character '…'
      "" No ellipsis, just display the truncated string

      Note that not all fonts support all Unicode characters.

      Default value:
      "..."
      Since:
      JavaFX 2.2
    • getEllipsisString

      public final String getEllipsisString()
      Gets the value of the property ellipsisString.
      Property description:
      Specifies the string to display for the ellipsis when text is truncated.
      Ellipsis Table
      Examples
      "..." Default value for most locales
      " . . . "
      " [...] "
      "\u2026" The Unicode ellipsis character '…'
      "" No ellipsis, just display the truncated string

      Note that not all fonts support all Unicode characters.

      Default value:
      "..."
      Since:
      JavaFX 2.2
    • wrapTextProperty

      public final BooleanProperty wrapTextProperty()
      If a run of text exceeds the width of the Labeled, then this variable indicates whether the text should wrap onto another line.
      Default value:
      false
      See Also:
    • setWrapText

      public final void setWrapText(boolean value)
      Sets the value of the property wrapText.
      Property description:
      If a run of text exceeds the width of the Labeled, then this variable indicates whether the text should wrap onto another line.
      Default value:
      false
    • isWrapText

      public final boolean isWrapText()
      Gets the value of the property wrapText.
      Property description:
      If a run of text exceeds the width of the Labeled, then this variable indicates whether the text should wrap onto another line.
      Default value:
      false
    • getContentBias

      public Orientation getContentBias()
      If wrapText is true, then contentBias will be HORIZONTAL, otherwise it is null.
      Overrides:
      getContentBias in class Node
      Returns:
      orientation of width/height dependency or null if there is none
      See Also:
    • fontProperty

      public final ObjectProperty<Font> fontProperty()
      The default font to use for text in the Labeled. If the Label's text is rich text then this font may or may not be used depending on the font information embedded in the rich text, but in any case where a default font is required, this font will be used.
      Default value:
      Font.getDefault()
      See Also:
    • setFont

      public final void setFont(Font value)
      Sets the value of the property font.
      Property description:
      The default font to use for text in the Labeled. If the Label's text is rich text then this font may or may not be used depending on the font information embedded in the rich text, but in any case where a default font is required, this font will be used.
      Default value:
      Font.getDefault()
    • getFont

      public final Font getFont()
      Gets the value of the property font.
      Property description:
      The default font to use for text in the Labeled. If the Label's text is rich text then this font may or may not be used depending on the font information embedded in the rich text, but in any case where a default font is required, this font will be used.
      Default value:
      Font.getDefault()
    • graphicProperty

      public final ObjectProperty<Node> graphicProperty()
      An optional icon for the Labeled. This can be positioned relative to the text by using setContentDisplay(javafx.scene.control.ContentDisplay). The node specified for this variable cannot appear elsewhere in the scene graph, otherwise the IllegalArgumentException is thrown. See the class description of Node for more detail.
      Default value:
      null
      See Also:
    • setGraphic

      public final void setGraphic(Node value)
      Sets the value of the property graphic.
      Property description:
      An optional icon for the Labeled. This can be positioned relative to the text by using setContentDisplay(javafx.scene.control.ContentDisplay). The node specified for this variable cannot appear elsewhere in the scene graph, otherwise the IllegalArgumentException is thrown. See the class description of Node for more detail.
      Default value:
      null
    • getGraphic

      public final Node getGraphic()
      Gets the value of the property graphic.
      Property description:
      An optional icon for the Labeled. This can be positioned relative to the text by using setContentDisplay(javafx.scene.control.ContentDisplay). The node specified for this variable cannot appear elsewhere in the scene graph, otherwise the IllegalArgumentException is thrown. See the class description of Node for more detail.
      Default value:
      null
    • underlineProperty

      public final BooleanProperty underlineProperty()
      Whether all text should be underlined.
      Default value:
      false
      See Also:
    • setUnderline

      public final void setUnderline(boolean value)
      Sets the value of the property underline.
      Property description:
      Whether all text should be underlined.
      Default value:
      false
    • isUnderline

      public final boolean isUnderline()
      Gets the value of the property underline.
      Property description:
      Whether all text should be underlined.
      Default value:
      false
    • lineSpacingProperty

      public final DoubleProperty lineSpacingProperty()
      Specifies the space in pixel between lines.
      Default value:
      0
      Since:
      JavaFX 8.0
      See Also:
    • setLineSpacing

      public final void setLineSpacing(double value)
      Sets the value of the property lineSpacing.
      Property description:
      Specifies the space in pixel between lines.
      Default value:
      0
      Since:
      JavaFX 8.0
    • getLineSpacing

      public final double getLineSpacing()
      Gets the value of the property lineSpacing.
      Property description:
      Specifies the space in pixel between lines.
      Default value:
      0
      Since:
      JavaFX 8.0
    • contentDisplayProperty

      public final ObjectProperty<ContentDisplay> contentDisplayProperty()
      Specifies the positioning of the graphic relative to the text.
      Default value:
      ContentDisplay.LEFT
      See Also:
    • setContentDisplay

      public final void setContentDisplay(ContentDisplay value)
      Sets the value of the property contentDisplay.
      Property description:
      Specifies the positioning of the graphic relative to the text.
      Default value:
      ContentDisplay.LEFT
    • getContentDisplay

      public final ContentDisplay getContentDisplay()
      Gets the value of the property contentDisplay.
      Property description:
      Specifies the positioning of the graphic relative to the text.
      Default value:
      ContentDisplay.LEFT
    • labelPaddingProperty

      public final ReadOnlyObjectProperty<Insets> labelPaddingProperty()
      The padding around the Labeled's text and graphic content. By default labelPadding is Insets.EMPTY and cannot be set to null. Subclasses may add nodes outside this padding and inside the Labeled's padding. This property can only be set from CSS.
      Default value:
      Insets.EMPTY
      See Also:
    • getLabelPadding

      public final Insets getLabelPadding()
      Gets the value of the property labelPadding.
      Property description:
      The padding around the Labeled's text and graphic content. By default labelPadding is Insets.EMPTY and cannot be set to null. Subclasses may add nodes outside this padding and inside the Labeled's padding. This property can only be set from CSS.
      Default value:
      Insets.EMPTY
    • graphicTextGapProperty

      public final DoubleProperty graphicTextGapProperty()
      The amount of space between the graphic and text
      Default value:
      4
      See Also:
    • setGraphicTextGap

      public final void setGraphicTextGap(double value)
      Sets the value of the property graphicTextGap.
      Property description:
      The amount of space between the graphic and text
      Default value:
      4
    • getGraphicTextGap

      public final double getGraphicTextGap()
      Gets the value of the property graphicTextGap.
      Property description:
      The amount of space between the graphic and text
      Default value:
      4
    • setTextFill

      public final void setTextFill(Paint value)
      Sets the value of the property textFill.
      Property description:
      The Paint used to fill the text.
      Default value:
      Color.BLACK
    • getTextFill

      public final Paint getTextFill()
      Gets the value of the property textFill.
      Property description:
      The Paint used to fill the text.
      Default value:
      Color.BLACK
    • textFillProperty

      public final ObjectProperty<Paint> textFillProperty()
      The Paint used to fill the text.
      Default value:
      Color.BLACK
      See Also:
    • setMnemonicParsing

      public final void setMnemonicParsing(boolean value)
      Sets the value of the property mnemonicParsing.
      Property description:
      MnemonicParsing property to enable/disable text parsing. If this is set to true, then the Label text will be parsed to see if it contains the mnemonic parsing character '_'. When a mnemonic is detected the key combination will be determined based on the succeeding character, and the mnemonic added.
      Default value:
      false; true for some Controls.
    • isMnemonicParsing

      public final boolean isMnemonicParsing()
      Gets the value of the property mnemonicParsing.
      Property description:
      MnemonicParsing property to enable/disable text parsing. If this is set to true, then the Label text will be parsed to see if it contains the mnemonic parsing character '_'. When a mnemonic is detected the key combination will be determined based on the succeeding character, and the mnemonic added.
      Default value:
      false; true for some Controls.
    • mnemonicParsingProperty

      public final BooleanProperty mnemonicParsingProperty()
      MnemonicParsing property to enable/disable text parsing. If this is set to true, then the Label text will be parsed to see if it contains the mnemonic parsing character '_'. When a mnemonic is detected the key combination will be determined based on the succeeding character, and the mnemonic added.
      Default value:
      false; true for some Controls.
      See Also:
    • getInitialAlignment

      protected Pos getInitialAlignment()
      Returns the initial alignment state of this control, for use by the JavaFX CSS engine to correctly set its initial value. This method is overridden to use Pos.CENTER_LEFT initially.
      Returns:
      the initial alignment state of this control
      Since:
      9
    • getClassCssMetaData

      public static List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
      Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.
      Returns:
      the CssMetaData
      Since:
      JavaFX 8.0
    • getControlCssMetaData

      public List<CssMetaData<? extends Styleable,?>> getControlCssMetaData()
      Gets the unmodifiable list of the control's CSS-styleable properties.
      Overrides:
      getControlCssMetaData in class Control
      Returns:
      the unmodifiable list of the control's CSS-styleable properties
      Since:
      JavaFX 8.0