Top Description Inners Fields Constructors Methods
javafx.scene.control

public abstract Class Labeled

extends Control
Class Inheritance
Known Direct Subclasses
javafx.scene.control.TitledPane, javafx.scene.control.ButtonBase, javafx.scene.control.Cell, javafx.scene.control.Label
Annotations
@DefaultProperty:text
Imports
java.util.ArrayList, .Collections, .List, javafx.beans.DefaultProperty, javafx.beans.binding.Bindings, javafx.beans.property.BooleanProperty, .DoubleProperty, .ObjectProperty, .ReadOnlyBooleanProperty, .ReadOnlyBooleanWrapper, .ReadOnlyObjectProperty, .SimpleBooleanProperty, .SimpleStringProperty, .StringProperty, javafx.beans.value.WritableValue, javafx.css.CssMetaData, .FontCssMetaData, .StyleOrigin, .Styleable, .StyleableBooleanProperty, .StyleableDoubleProperty, .StyleableObjectProperty, .StyleableProperty, .StyleableStringProperty, javafx.css.converter.BooleanConverter, .EnumConverter, .InsetsConverter, .PaintConverter, .SizeConverter, .StringConverter, javafx.geometry.Insets, .Orientation, .Pos, javafx.scene.Node, javafx.scene.image.Image, .ImageView, javafx.scene.paint.Color, .Paint, javafx.scene.text.Font, .TextAlignment, com.sun.javafx.css.StyleManager, com.sun.javafx.scene.NodeHelper, com.sun.javafx.scene.control.LabeledHelper

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
Button, Label, ToggleButton

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private ObjectProperty<Pos>
private ObjectProperty<ContentDisplay>
private static final String
private StringProperty
private ObjectProperty<Font>
private ObjectProperty<Node>
private DoubleProperty
private StyleableStringProperty
private ObjectProperty<Insets>
private DoubleProperty
private BooleanProperty
mnemonicParsing

MnemonicParsing property to enable/disable text parsing.

private StringProperty
private ObjectProperty<TextAlignment>
private ObjectProperty<Paint>
textFill

The Paint used to fill the text.

private ObjectProperty<OverrunStyle>
private ReadOnlyBooleanWrapper
textTruncated

Indicates whether the text has been truncated because it cannot fit into the available width.

private BooleanProperty
private BooleanProperty

Constructor Summary

AccessConstructor and Description
public
Labeled()

Creates a Label with no text and graphic

public
Labeled(String
The text for the label.
text
)

Creates a Label with text

public
Labeled(String
The text for the label.
text
,
Node
The graphic for the label.
graphic
)

Creates a Label with text and a graphic

Method Summary

Modifier and TypeMethod and Description
public final ObjectProperty<Pos>

Returns:

the alignment within this labeled
alignmentProperty
()

Specifies how the text and graphic within the Labeled should be aligned when there is empty space within the Labeled.

public final ObjectProperty<ContentDisplay>

Returns:

content display property of this labeled
contentDisplayProperty
()

Specifies the positioning of the graphic relative to the text.

public final StringProperty

Returns:

the ellipsis property on the string to display for the ellipsis when text is truncated
ellipsisStringProperty
()

Specifies the string to display for the ellipsis when text is truncated.

public final ObjectProperty<Font>

Returns:

the default font to use for text in this labeled
fontProperty
()

The default font to use for text in the Labeled.

public final Pos
public static List<CssMetaData<? extends Styleable, ?>>

Returns:

the CssMetaData
getClassCssMetaData
()

Hides javafx.scene.control.Control.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

public Orientation

Returns:

orientation of width/height dependency or null if there is none
getContentBias
()

Overrides javafx.scene.Node.getContentBias.

If wrapText is true, then contentBias will be HORIZONTAL, otherwise it is null.

public final ContentDisplay
public List<CssMetaData<? extends Styleable, ?>>
getControlCssMetaData()

Overrides javafx.scene.control.Control.getControlCssMetaData.

Gets the unmodifiable list of the control's CSS-styleable properties.

public final String
public final Font
public final Node
public final double
protected Pos

Returns:

the initial alignment state of this control
getInitialAlignment
()

Returns the initial alignment state of this control, for use by the JavaFX CSS engine to correctly set its initial value.

public final Insets
public final double
public final String
public final TextAlignment
public final Paint
public final OverrunStyle
public final ObjectProperty<Node>

Returns:

the optional icon for this labeled
graphicProperty
()

An optional icon for the Labeled.

public final DoubleProperty

Returns:

the graphics text gap property of this labeled
graphicTextGapProperty
()

The amount of space between the graphic and text

private StyleableStringProperty
imageUrlProperty()

The imageUrl property is set from CSS and then the graphic property is set from the invalidated method.

public final boolean
public final boolean
public final boolean
public final boolean
public final ReadOnlyObjectProperty<Insets>

Returns:

the label padding property of this labeled
labelPaddingProperty
()

The padding around the Labeled's text and graphic content.

private ObjectProperty<Insets>
public final DoubleProperty

Returns:

the line spacing property between lines in this labeled
lineSpacingProperty
()

Specifies the space in pixel between lines.

public final BooleanProperty
public final void
public final void
public final void
public final void
setFont(Font value)

public final void
public final void
setGraphicTextGap(double value)

private void
public final void
setLineSpacing(double value)

public final void
setMnemonicParsing(boolean value)

public final void
setText(String value)

public final void
public final void
public final void
private final void
setTextTruncated(boolean on)

public final void
setUnderline(boolean value)

public final void
setWrapText(boolean value)

public final ObjectProperty<TextAlignment>

Returns:

the alignment of lines of text within this labeled
textAlignmentProperty
()

Specifies the behavior for lines of text when text is multiline.

public final ObjectProperty<Paint>
public final ObjectProperty<OverrunStyle>

Returns:

the overrun behavior if the text exceeds the available space
textOverrunProperty
()

Specifies the behavior to use if the text of the Labeled exceeds the available space for rendering the text.

public final StringProperty

Returns:

the text to display in the label
textProperty
()

The text to display in the label.

private ReadOnlyBooleanWrapper
public final ReadOnlyBooleanProperty
public String
toString()

Overrides javafx.scene.Node.toString.

Returns a string representation for the object.

public final BooleanProperty

Returns:

the underline property of all text in this labeled
underlineProperty
()

Whether all text should be underlined.

public final BooleanProperty

Returns:

the wrap property if a run of text exceeds the width of the Labeled
wrapTextProperty
()

If a run of text exceeds the width of the Labeled, then this variable indicates whether the text should wrap onto another line.

Inherited from javafx.scene.control.Control:
computeMaxHeightcomputeMaxWidthcomputeMinHeightcomputeMinWidthcomputePrefHeightcomputePrefWidthcontextMenuPropertycreateDefaultSkinexecuteAccessibleActiongetBaselineOffsetgetContextMenugetControlChildrengetCssMetaDatagetInitialFocusTraversablegetSkingetTooltipisResizablelayoutChildrenloadSkinClassqueryAccessibleAttributesetContextMenusetSkinsetTooltipskinClassNamePropertyskinPropertytooltipProperty

Field Detail

alignmentback to summary
private ObjectProperty<Pos> alignment
contentDisplayback to summary
private ObjectProperty<ContentDisplay> contentDisplay
DEFAULT_ELLIPSIS_STRINGback to summary
private static final String DEFAULT_ELLIPSIS_STRING
ellipsisStringback to summary
private StringProperty ellipsisString
fontback to summary
private ObjectProperty<Font> font
graphicback to summary
private ObjectProperty<Node> graphic
graphicTextGapback to summary
private DoubleProperty graphicTextGap
imageUrlback to summary
private StyleableStringProperty imageUrl
labelPaddingback to summary
private ObjectProperty<Insets> labelPadding
lineSpacingback to summary
private DoubleProperty lineSpacing
mnemonicParsingback to summary
private BooleanProperty mnemonicParsing

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.
textback to summary
private StringProperty text
textAlignmentback to summary
private ObjectProperty<TextAlignment> textAlignment
textFillback to summary
private ObjectProperty<Paint> textFill

The Paint used to fill the text.

Default Value
Color.BLACK
textOverrunback to summary
private ObjectProperty<OverrunStyle> textOverrun
textTruncatedback to summary
private ReadOnlyBooleanWrapper textTruncated

Indicates whether the text has been truncated because it cannot fit into the available width.

When truncated, the ellipsisString gets inserted in the place dictated by the textOverrun property.

Since
23
underlineback to summary
private BooleanProperty underline
wrapTextback to summary
private BooleanProperty wrapText

Constructor Detail

Labeledback to summary
public Labeled()

Creates a Label with no text and graphic

Labeledback to summary
public Labeled(String text)

Creates a Label with text

Parameters
text:String

The text for the label.

Labeledback to summary
public Labeled(String text, Node graphic)

Creates a Label with text and a graphic

Parameters
text:String

The text for the label.

graphic:Node

The graphic for the label.

Method Detail

alignmentPropertyback to summary
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.

Returns:ObjectProperty<Pos>

the alignment within this labeled

Default Value
Pos.CENTER_LEFT
contentDisplayPropertyback to summary
public final ObjectProperty<ContentDisplay> contentDisplayProperty()

Specifies the positioning of the graphic relative to the text.

Returns:ObjectProperty<ContentDisplay>

content display property of this labeled

Default Value
ContentDisplay.LEFT
ellipsisStringPropertyback to summary
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.

Returns:StringProperty

the ellipsis property on the string to display for the ellipsis when text is truncated

Default Value
"..."
Since
JavaFX 2.2
See Also
Wikipedia:ellipsis
fontPropertyback to summary
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.

Returns:ObjectProperty<Font>

the default font to use for text in this labeled

Default Value
Font#getDefault()
getAlignmentback to summary
public final Pos getAlignment()
getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides javafx.scene.control.Control.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

Returns:List<CssMetaData<? extends Styleable, ?>>

the CssMetaData

Since
JavaFX 8.0
getContentBiasback to summary
public Orientation getContentBias()

Overrides javafx.scene.Node.getContentBias.

If wrapText is true, then contentBias will be HORIZONTAL, otherwise it is null.

Returns:Orientation

orientation of width/height dependency or null if there is none

Annotations
@Override
getContentDisplayback to summary
public final ContentDisplay getContentDisplay()
getControlCssMetaDataback to summary
public List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData()

Overrides javafx.scene.control.Control.getControlCssMetaData.

Doc from javafx.scene.control.Control.getControlCssMetaData.

Gets the unmodifiable list of the control's CSS-styleable properties.

Annotations
@Override
Since
JavaFX 8.0
getEllipsisStringback to summary
public final String getEllipsisString()
getFontback to summary
public final Font getFont()
getGraphicback to summary
public final Node getGraphic()
getGraphicTextGapback to summary
public final double getGraphicTextGap()
getInitialAlignmentback to summary
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:Pos

the initial alignment state of this control

Since
9
getLabelPaddingback to summary
public final Insets getLabelPadding()
getLineSpacingback to summary
public final double getLineSpacing()
getTextback to summary
public final String getText()
getTextAlignmentback to summary
public final TextAlignment getTextAlignment()
getTextFillback to summary
public final Paint getTextFill()
getTextOverrunback to summary
public final OverrunStyle getTextOverrun()
graphicPropertyback to summary
public final ObjectProperty<Node> graphicProperty()

An optional icon for the Labeled. This can be positioned relative to the text by using setContentDisplay. 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.

Returns:ObjectProperty<Node>

the optional icon for this labeled

Default Value
null
graphicTextGapPropertyback to summary
public final DoubleProperty graphicTextGapProperty()

The amount of space between the graphic and text

Returns:DoubleProperty

the graphics text gap property of this labeled

Default Value
4
imageUrlPropertyback to summary
private StyleableStringProperty imageUrlProperty()

The imageUrl property is set from CSS and then the graphic property is set from the invalidated method. This ensures that the same image isn't reloaded.

isMnemonicParsingback to summary
public final boolean isMnemonicParsing()
isTextTruncatedback to summary
public final boolean isTextTruncated()
isUnderlineback to summary
public final boolean isUnderline()
isWrapTextback to summary
public final boolean isWrapText()
labelPaddingPropertyback to summary
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.

Returns:ReadOnlyObjectProperty<Insets>

the label padding property of this labeled

Default Value
Insets.EMPTY
labelPaddingPropertyImplback to summary
private ObjectProperty<Insets> labelPaddingPropertyImpl()
lineSpacingPropertyback to summary
public final DoubleProperty lineSpacingProperty()

Specifies the space in pixel between lines.

Returns:DoubleProperty

the line spacing property between lines in this labeled

Default Value
0
Since
JavaFX 8.0
mnemonicParsingPropertyback to summary
public final BooleanProperty mnemonicParsingProperty()
setAlignmentback to summary
public final void setAlignment(Pos value)
setContentDisplayback to summary
public final void setContentDisplay(ContentDisplay value)
setEllipsisStringback to summary
public final void setEllipsisString(String value)
setFontback to summary
public final void setFont(Font value)
setGraphicback to summary
public final void setGraphic(Node value)
setGraphicTextGapback to summary
public final void setGraphicTextGap(double value)
setLabelPaddingback to summary
private void setLabelPadding(Insets value)
setLineSpacingback to summary
public final void setLineSpacing(double value)
setMnemonicParsingback to summary
public final void setMnemonicParsing(boolean value)
setTextback to summary
public final void setText(String value)
setTextAlignmentback to summary
public final void setTextAlignment(TextAlignment value)
setTextFillback to summary
public final void setTextFill(Paint value)
setTextOverrunback to summary
public final void setTextOverrun(OverrunStyle value)
setTextTruncatedback to summary
private final void setTextTruncated(boolean on)
setUnderlineback to summary
public final void setUnderline(boolean value)
setWrapTextback to summary
public final void setWrapText(boolean value)
textAlignmentPropertyback to summary
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.

Returns:ObjectProperty<TextAlignment>

the alignment of lines of text within this labeled

Default Value
TextAlignment.LEFT
textFillPropertyback to summary
public final ObjectProperty<Paint> textFillProperty()
textOverrunPropertyback to summary
public final ObjectProperty<OverrunStyle> textOverrunProperty()

Specifies the behavior to use if the text of the Labeled exceeds the available space for rendering the text.

Returns:ObjectProperty<OverrunStyle>

the overrun behavior if the text exceeds the available space

Default Value
OverrunStyle.ELLIPSIS
textPropertyback to summary
public final StringProperty textProperty()

The text to display in the label. The text may be null.

Returns:StringProperty

the text to display in the label

Default Value
empty string
textTruncatedback to summary
private ReadOnlyBooleanWrapper textTruncated()
textTruncatedPropertyback to summary
public final ReadOnlyBooleanProperty textTruncatedProperty()
toStringback to summary
public String toString()

Overrides javafx.scene.Node.toString.

Doc from javafx.scene.Node.toString.

Returns a string representation for the object.

Annotations
@Override
underlinePropertyback to summary
public final BooleanProperty underlineProperty()

Whether all text should be underlined.

Returns:BooleanProperty

the underline property of all text in this labeled

Default Value
false
wrapTextPropertyback to summary
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.

Returns:BooleanProperty

the wrap property if a run of text exceeds the width of the Labeled

Default Value
false
javafx.scene.control back to summary

private Class Labeled.StyleableProperties

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final CssMetaData<Labeled, Pos>
private static final CssMetaData<Labeled, ContentDisplay>
private static final CssMetaData<Labeled, String>
private static final FontCssMetaData<Labeled>
private static final CssMetaData<Labeled, String>
private static final CssMetaData<Labeled, Number>
private static final CssMetaData<Labeled, Insets>
private static final CssMetaData<Labeled, Number>
private static final List<CssMetaData<? extends Styleable, ?>>
private static final CssMetaData<Labeled, TextAlignment>
private static final CssMetaData<Labeled, Paint>
private static final CssMetaData<Labeled, OverrunStyle>
private static final CssMetaData<Labeled, Boolean>
private static final CssMetaData<Labeled, Boolean>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALIGNMENTback to summary
private static final CssMetaData<Labeled, Pos> ALIGNMENT
CONTENT_DISPLAYback to summary
private static final CssMetaData<Labeled, ContentDisplay> CONTENT_DISPLAY
ELLIPSIS_STRINGback to summary
private static final CssMetaData<Labeled, String> ELLIPSIS_STRING
FONTback to summary
private static final FontCssMetaData<Labeled> FONT
GRAPHICback to summary
private static final CssMetaData<Labeled, String> GRAPHIC
GRAPHIC_TEXT_GAPback to summary
private static final CssMetaData<Labeled, Number> GRAPHIC_TEXT_GAP
LABEL_PADDINGback to summary
private static final CssMetaData<Labeled, Insets> LABEL_PADDING
LINE_SPACINGback to summary
private static final CssMetaData<Labeled, Number> LINE_SPACING
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES
TEXT_ALIGNMENTback to summary
private static final CssMetaData<Labeled, TextAlignment> TEXT_ALIGNMENT
TEXT_FILLback to summary
private static final CssMetaData<Labeled, Paint> TEXT_FILL
TEXT_OVERRUNback to summary
private static final CssMetaData<Labeled, OverrunStyle> TEXT_OVERRUN
UNDERLINEback to summary
private static final CssMetaData<Labeled, Boolean> UNDERLINE
WRAP_TEXTback to summary
private static final CssMetaData<Labeled, Boolean> WRAP_TEXT

Constructor Detail

StyleablePropertiesback to summary
private StyleableProperties()