public abstract class Labeled extends Control
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);
Button
,
Label
,
ToggleButton
Type | Property and Description |
---|---|
<any> |
alignment
Specifies how the text and graphic within the Labeled should be
aligned when there is empty space within the Labeled.
|
<any> |
contentDisplay
Specifies the positioning of the graphic relative to the text.
|
StringProperty |
ellipsisString
Specifies the string to display for the ellipsis when text is truncated.
|
<any> |
font
The default font to use for text in the Labeled.
|
<any> |
graphic
An optional icon for the Labeled.
|
DoubleProperty |
graphicTextGap
The amount of space between the graphic and text
|
<any> |
labelPadding
The padding around the Labeled's text and graphic content.
|
DoubleProperty |
lineSpacing
Specifies the space in pixel between lines.
|
BooleanProperty |
mnemonicParsing
MnemonicParsing property to enable/disable text parsing.
|
<any> |
textAlignment
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. |
<any> |
textFill
The
Paint used to fill the text. |
<any> |
textOverrun
Specifies the behavior to use if the text of the
Labeled
exceeds the available space for rendering the text. |
StringProperty |
text
The text to display in the label.
|
BooleanProperty |
underline
Whether all text should be underlined.
|
BooleanProperty |
wrapText
If a run of text exceeds the width of the Labeled, then this variable
indicates whether the text should wrap onto another line.
|
contextMenuProperty, skinClassNameProperty, skinProperty, tooltipProperty
Modifier and Type | Class and Description |
---|---|
private static class |
Labeled.StyleableProperties |
Modifier and Type | Field and Description |
---|---|
private <any> |
alignment |
private <any> |
contentDisplay |
private static java.lang.String |
DEFAULT_ELLIPSIS_STRING |
private StringProperty |
ellipsisString |
private <any> |
font |
private <any> |
graphic |
private DoubleProperty |
graphicTextGap |
private StyleableStringProperty |
imageUrl |
private <any> |
labelPadding |
private DoubleProperty |
lineSpacing |
private BooleanProperty |
mnemonicParsing
MnemonicParsing property to enable/disable text parsing.
|
private StringProperty |
text |
private <any> |
textAlignment |
private <any> |
textFill
The
Paint used to fill the text. |
private <any> |
textOverrun |
private BooleanProperty |
underline |
private BooleanProperty |
wrapText |
Constructor and Description |
---|
Labeled()
Creates a Label with no text and graphic
|
Labeled(java.lang.String text)
Creates a Label with text
|
Labeled(java.lang.String text,
Node graphic)
Creates a Label with text and a graphic
|
Modifier and Type | Method and Description |
---|---|
<any> |
alignmentProperty()
Specifies how the text and graphic within the Labeled should be
aligned when there is empty space within the Labeled.
|
<any> |
contentDisplayProperty()
Specifies the positioning of the graphic relative to the text.
|
StringProperty |
ellipsisStringProperty()
Specifies the string to display for the ellipsis when text is truncated.
|
<any> |
fontProperty()
The default font to use for text in the Labeled.
|
Pos |
getAlignment()
Gets the value of the property alignment.
|
static java.util.List<<any>> |
getClassCssMetaData() |
Orientation |
getContentBias()
If wrapText is true, then contentBias will be HORIZONTAL, otherwise it is null.
|
ContentDisplay |
getContentDisplay()
Gets the value of the property contentDisplay.
|
java.util.List<<any>> |
getControlCssMetaData() |
java.lang.String |
getEllipsisString()
Gets the value of the property ellipsisString.
|
Font |
getFont()
Gets the value of the property font.
|
Node |
getGraphic()
Gets the value of the property graphic.
|
double |
getGraphicTextGap()
Gets the value of the property graphicTextGap.
|
protected Pos |
getInitialAlignment()
Returns the initial alignment state of this control, for use
by the JavaFX CSS engine to correctly set its initial value.
|
Insets |
getLabelPadding()
Gets the value of the property labelPadding.
|
double |
getLineSpacing()
Gets the value of the property lineSpacing.
|
java.lang.String |
getText()
Gets the value of the property text.
|
TextAlignment |
getTextAlignment()
Gets the value of the property textAlignment.
|
Paint |
getTextFill()
Gets the value of the property textFill.
|
OverrunStyle |
getTextOverrun()
Gets the value of the property textOverrun.
|
<any> |
graphicProperty()
An optional icon for the Labeled.
|
DoubleProperty |
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.
|
boolean |
isMnemonicParsing()
Gets the value of the property mnemonicParsing.
|
boolean |
isUnderline()
Gets the value of the property underline.
|
boolean |
isWrapText()
Gets the value of the property wrapText.
|
<any> |
labelPaddingProperty()
The padding around the Labeled's text and graphic content.
|
private <any> |
labelPaddingPropertyImpl() |
DoubleProperty |
lineSpacingProperty()
Specifies the space in pixel between lines.
|
BooleanProperty |
mnemonicParsingProperty()
MnemonicParsing property to enable/disable text parsing.
|
void |
setAlignment(Pos value)
Sets the value of the property alignment.
|
void |
setContentDisplay(ContentDisplay value)
Sets the value of the property contentDisplay.
|
void |
setEllipsisString(java.lang.String value)
Sets the value of the property ellipsisString.
|
void |
setFont(Font value)
Sets the value of the property font.
|
void |
setGraphic(Node value)
Sets the value of the property graphic.
|
void |
setGraphicTextGap(double value)
Sets the value of the property graphicTextGap.
|
private void |
setLabelPadding(Insets value) |
void |
setLineSpacing(double value)
Sets the value of the property lineSpacing.
|
void |
setMnemonicParsing(boolean value)
Sets the value of the property mnemonicParsing.
|
void |
setText(java.lang.String value)
Sets the value of the property text.
|
void |
setTextAlignment(TextAlignment value)
Sets the value of the property textAlignment.
|
void |
setTextFill(Paint value)
Sets the value of the property textFill.
|
void |
setTextOverrun(OverrunStyle value)
Sets the value of the property textOverrun.
|
void |
setUnderline(boolean value)
Sets the value of the property underline.
|
void |
setWrapText(boolean value)
Sets the value of the property wrapText.
|
<any> |
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. |
<any> |
textFillProperty()
The
Paint used to fill the text. |
<any> |
textOverrunProperty()
Specifies the behavior to use if the text of the
Labeled
exceeds the available space for rendering the text. |
StringProperty |
textProperty()
The text to display in the label.
|
java.lang.String |
toString() |
BooleanProperty |
underlineProperty()
Whether all text should be underlined.
|
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.
|
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, createDefaultSkin, executeAccessibleAction, getBaselineOffset, getContextMenu, getControlChildren, getCssMetaData, getInitialFocusTraversable, getSkin, getTooltip, isResizable, layoutChildren, loadSkinClass, queryAccessibleAttribute, setContextMenu, setSkin, setTooltip, skinClassNameProperty, skinProperty, tooltipProperty
public final StringProperty textProperty
getText()
,
setText(String)
public final <any> alignmentProperty
getAlignment()
,
setAlignment(Pos)
public final <any> textAlignmentProperty
contentDisplayProperty()
which affects the graphic and text, this setting
only affects multiple lines of text relative to the text bounds.public final <any> textOverrunProperty
Labeled
exceeds the available space for rendering the text.getTextOverrun()
,
setTextOverrun(OverrunStyle)
public final StringProperty ellipsisStringProperty
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.
getEllipsisString()
,
setEllipsisString(String)
public final BooleanProperty wrapTextProperty
isWrapText()
,
setWrapText(boolean)
public final <any> fontProperty
getFont()
,
setFont(Font)
public final <any> graphicProperty
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.getGraphic()
,
setGraphic(Node)
public final BooleanProperty underlineProperty
isUnderline()
,
setUnderline(boolean)
public final DoubleProperty lineSpacingProperty
getLineSpacing()
,
setLineSpacing(double)
public final <any> contentDisplayProperty
public final <any> labelPaddingProperty
getLabelPadding()
public final DoubleProperty graphicTextGapProperty
getGraphicTextGap()
,
setGraphicTextGap(double)
public final <any> textFillProperty
Paint
used to fill the text.getTextFill()
,
setTextFill(Paint)
public final BooleanProperty mnemonicParsingProperty
The default value for Labeled is false, but it is enabled by default on some Controls.
isMnemonicParsing()
,
setMnemonicParsing(boolean)
private static final java.lang.String DEFAULT_ELLIPSIS_STRING
private StringProperty text
private <any> alignment
private <any> textAlignment
private <any> textOverrun
private StringProperty ellipsisString
private BooleanProperty wrapText
private <any> font
private <any> graphic
private StyleableStringProperty imageUrl
private BooleanProperty underline
private DoubleProperty lineSpacing
private <any> contentDisplay
private <any> labelPadding
private DoubleProperty graphicTextGap
private <any> textFill
Paint
used to fill the text.private BooleanProperty mnemonicParsing
The default value for Labeled is false, but it is enabled by default on some Controls.
public Labeled()
public Labeled(java.lang.String text)
text
- The text for the label.public Labeled(java.lang.String text, Node graphic)
text
- The text for the label.graphic
- The graphic for the label.public final StringProperty textProperty()
getText()
,
setText(String)
public final void setText(java.lang.String value)
public final java.lang.String getText()
public final <any> alignmentProperty()
getAlignment()
,
setAlignment(Pos)
public final void setAlignment(Pos value)
public final Pos getAlignment()
public final <any> textAlignmentProperty()
contentDisplayProperty()
which affects the graphic and text, this setting
only affects multiple lines of text relative to the text bounds.public final void setTextAlignment(TextAlignment value)
public final TextAlignment getTextAlignment()
public final <any> textOverrunProperty()
Labeled
exceeds the available space for rendering the text.getTextOverrun()
,
setTextOverrun(OverrunStyle)
public final void setTextOverrun(OverrunStyle value)
public final OverrunStyle getTextOverrun()
public final StringProperty ellipsisStringProperty()
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.
getEllipsisString()
,
setEllipsisString(String)
public final void setEllipsisString(java.lang.String value)
public final java.lang.String getEllipsisString()
public final BooleanProperty wrapTextProperty()
isWrapText()
,
setWrapText(boolean)
public final void setWrapText(boolean value)
public final boolean isWrapText()
public Orientation getContentBias()
public final <any> fontProperty()
getFont()
,
setFont(Font)
public final void setFont(Font value)
public final Font getFont()
public final <any> graphicProperty()
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.getGraphic()
,
setGraphic(Node)
public final void setGraphic(Node value)
public final Node getGraphic()
private StyleableStringProperty imageUrlProperty()
public final BooleanProperty underlineProperty()
isUnderline()
,
setUnderline(boolean)
public final void setUnderline(boolean value)
public final boolean isUnderline()
public final DoubleProperty lineSpacingProperty()
getLineSpacing()
,
setLineSpacing(double)
public final void setLineSpacing(double value)
public final double getLineSpacing()
public final <any> contentDisplayProperty()
public final void setContentDisplay(ContentDisplay value)
public final ContentDisplay getContentDisplay()
public final <any> labelPaddingProperty()
getLabelPadding()
private <any> labelPaddingPropertyImpl()
private void setLabelPadding(Insets value)
public final Insets getLabelPadding()
public final DoubleProperty graphicTextGapProperty()
getGraphicTextGap()
,
setGraphicTextGap(double)
public final void setGraphicTextGap(double value)
public final double getGraphicTextGap()
public final void setTextFill(Paint value)
public final Paint getTextFill()
public final <any> textFillProperty()
Paint
used to fill the text.getTextFill()
,
setTextFill(Paint)
public final void setMnemonicParsing(boolean value)
public final boolean isMnemonicParsing()
public final BooleanProperty mnemonicParsingProperty()
The default value for Labeled is false, but it is enabled by default on some Controls.
isMnemonicParsing()
,
setMnemonicParsing(boolean)
public java.lang.String toString()
protected Pos getInitialAlignment()
public static java.util.List<<any>> getClassCssMetaData()
public java.util.List<<any>> getControlCssMetaData()
getControlCssMetaData
in class Control