@DefaultProperty(value="text") public class Text extends Shape
Text
class defines a node that displays a text.
Paragraphs are separated by '\n'
and the text is wrapped on
paragraph boundaries.
import javafx.scene.text.*; Text t = new Text(10, 50, "This is a test"); t.setFont(new Font(20));
import javafx.scene.text.*; Text t = new Text(); text.setFont(new Font(20)); text.setText("First row\nSecond row");
import javafx.scene.text.*; Text t = new Text(); text.setFont(new Font(20)); text.setWrappingWidth(200); text.setTextAlignment(TextAlignment.JUSTIFY) text.setText("The quick brown fox jumps over the lazy dog");
Type | Property and Description |
---|---|
ReadOnlyDoubleProperty |
baselineOffset
The 'alphabetic' (or roman) baseline offset from the Text node's
layoutBounds.minY location.
|
ObjectProperty<TextBoundsType> |
boundsType
Determines how the bounds of the text node are calculated.
|
ObjectProperty<Font> |
font
Defines the font of text.
|
ObjectProperty<FontSmoothingType> |
fontSmoothingType
Specifies a requested font smoothing type : gray or LCD.
|
DoubleProperty |
lineSpacing
Defines the vertical space in pixel between lines.
|
BooleanProperty |
strikethrough
Defines if each line of text should have a line through it.
|
ObjectProperty<TextAlignment> |
textAlignment
Defines horizontal text alignment in the bounding box.
|
ObjectProperty<VPos> |
textOrigin
Defines the origin of text coordinate system in local coordinates.
|
StringProperty |
text
Defines text string that is to be displayed.
|
BooleanProperty |
underline
Defines if each line of text should have a line below it.
|
DoubleProperty |
wrappingWidth
Defines a width constraint for the text in user space coordinates,
e.g.
|
DoubleProperty |
x
Defines the X coordinate of text origin.
|
DoubleProperty |
y
Defines the Y coordinate of text origin.
|
fill, smooth, strokeDashOffset, strokeLineCap, strokeLineJoin, strokeMiterLimit, stroke, strokeType, strokeWidth
accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, visible
BASELINE_OFFSET_SAME_AS_HEIGHT
Constructor and Description |
---|
Text()
Creates an empty instance of Text.
|
Text(double x,
double y,
String text)
Creates an instance of Text on the given coordinates containing the
given string.
|
Text(String text)
Creates an instance of Text containing the given string.
|
Modifier and Type | Method and Description |
---|---|
ReadOnlyDoubleProperty |
baselineOffsetProperty()
The 'alphabetic' (or roman) baseline offset from the Text node's
layoutBounds.minY location.
|
ObjectProperty<TextBoundsType> |
boundsTypeProperty()
Determines how the bounds of the text node are calculated.
|
ObjectProperty<Font> |
fontProperty()
Defines the font of text.
|
ObjectProperty<FontSmoothingType> |
fontSmoothingTypeProperty()
Specifies a requested font smoothing type : gray or LCD.
|
double |
getBaselineOffset()
Gets the value of the property baselineOffset.
|
TextBoundsType |
getBoundsType()
Gets the value of the property boundsType.
|
static List<CssMetaData<? extends Styleable,?>> |
getClassCssMetaData() |
List<CssMetaData<? extends Styleable,?>> |
getCssMetaData()
This method should delegate to
Node.getClassCssMetaData() so that
a Node's CssMetaData can be accessed without the need for reflection. |
Font |
getFont()
Gets the value of the property font.
|
FontSmoothingType |
getFontSmoothingType()
Gets the value of the property fontSmoothingType.
|
double |
getLineSpacing()
Gets the value of the property lineSpacing.
|
String |
getText()
Gets the value of the property text.
|
TextAlignment |
getTextAlignment()
Gets the value of the property textAlignment.
|
VPos |
getTextOrigin()
Gets the value of the property textOrigin.
|
double |
getWrappingWidth()
Gets the value of the property wrappingWidth.
|
double |
getX()
Gets the value of the property x.
|
double |
getY()
Gets the value of the property y.
|
boolean |
isStrikethrough()
Gets the value of the property strikethrough.
|
boolean |
isUnderline()
Gets the value of the property underline.
|
DoubleProperty |
lineSpacingProperty()
Defines the vertical space in pixel between lines.
|
Object |
queryAccessibleAttribute(AccessibleAttribute attribute,
Object... parameters)
This method is called by the assistive technology to request
the value for an attribute.
|
void |
setBoundsType(TextBoundsType value)
Sets the value of the property boundsType.
|
void |
setFont(Font value)
Sets the value of the property font.
|
void |
setFontSmoothingType(FontSmoothingType value)
Sets the value of the property fontSmoothingType.
|
void |
setLineSpacing(double spacing)
Sets the value of the property lineSpacing.
|
void |
setStrikethrough(boolean value)
Sets the value of the property strikethrough.
|
void |
setText(String value)
Sets the value of the property text.
|
void |
setTextAlignment(TextAlignment value)
Sets the value of the property textAlignment.
|
void |
setTextOrigin(VPos value)
Sets the value of the property textOrigin.
|
void |
setUnderline(boolean value)
Sets the value of the property underline.
|
void |
setWrappingWidth(double value)
Sets the value of the property wrappingWidth.
|
void |
setX(double value)
Sets the value of the property x.
|
void |
setY(double value)
Sets the value of the property y.
|
BooleanProperty |
strikethroughProperty()
Defines if each line of text should have a line through it.
|
ObjectProperty<TextAlignment> |
textAlignmentProperty()
Defines horizontal text alignment in the bounding box.
|
ObjectProperty<VPos> |
textOriginProperty()
Defines the origin of text coordinate system in local coordinates.
|
StringProperty |
textProperty()
Defines text string that is to be displayed.
|
String |
toString()
Returns a string representation of this
Text object. |
BooleanProperty |
underlineProperty()
Defines if each line of text should have a line below it.
|
boolean |
usesMirroring()
Determines whether a node should be mirrored when node orientation
is right-to-left.
|
DoubleProperty |
wrappingWidthProperty()
Defines a width constraint for the text in user space coordinates,
e.g.
|
DoubleProperty |
xProperty()
Defines the X coordinate of text origin.
|
DoubleProperty |
yProperty()
Defines the Y coordinate of text origin.
|
fillProperty, getFill, getStroke, getStrokeDashArray, getStrokeDashOffset, getStrokeLineCap, getStrokeLineJoin, getStrokeMiterLimit, getStrokeType, getStrokeWidth, intersect, isSmooth, setFill, setSmooth, setStroke, setStrokeDashOffset, setStrokeLineCap, setStrokeLineJoin, setStrokeMiterLimit, setStrokeType, setStrokeWidth, smoothProperty, strokeDashOffsetProperty, strokeLineCapProperty, strokeLineJoinProperty, strokeMiterLimitProperty, strokeProperty, strokeTypeProperty, strokeWidthProperty, subtract, union
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, executeAccessibleAction, fireEvent, focusedProperty, focusTraversableProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isResizable, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookup, lookupAll, managedProperty, maxHeight, maxWidth, minHeight, minWidth, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, prefHeight, prefWidth, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, resize, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, translateXProperty, translateYProperty, translateZProperty, visibleProperty
public final StringProperty textProperty
getText()
,
setText(String)
public final DoubleProperty xProperty
getX()
,
setX(double)
public final DoubleProperty yProperty
getY()
,
setY(double)
public final ObjectProperty<Font> fontProperty
getFont()
,
setFont(Font)
public final ObjectProperty<VPos> textOriginProperty
VPos.BASELINE
and
VPos.TOP
define the origin of the top row while
VPos.BOTTOM
defines the origin of the bottom row.getTextOrigin()
,
setTextOrigin(VPos)
public final ObjectProperty<TextBoundsType> boundsTypeProperty
TextBoundsType
for more information.getBoundsType()
,
setBoundsType(TextBoundsType)
public final DoubleProperty wrappingWidthProperty
> 0
text will be line wrapped as needed
to satisfy this constraint.getWrappingWidth()
,
setWrappingWidth(double)
public final BooleanProperty underlineProperty
isUnderline()
,
setUnderline(boolean)
public final BooleanProperty strikethroughProperty
isStrikethrough()
,
setStrikethrough(boolean)
public final ObjectProperty<TextAlignment> textAlignmentProperty
getTextAlignment()
,
setTextAlignment(TextAlignment)
public final DoubleProperty lineSpacingProperty
getLineSpacing()
,
setLineSpacing(double)
public final ReadOnlyDoubleProperty baselineOffsetProperty
getBaselineOffset()
public final ObjectProperty<FontSmoothingType> fontSmoothingTypeProperty
getFontSmoothingType()
,
setFontSmoothingType(FontSmoothingType)
public Text()
public Text(String text)
text
- text to be contained in the instancepublic Text(double x, double y, String text)
x
- the horizontal position of the texty
- the vertical position of the texttext
- text to be contained in the instancepublic boolean usesMirroring()
Node
When a node is mirrored, the origin is automatically moved to the
top right corner causing the node to layout children and draw from
right to left using a mirroring transformation. Some nodes may wish
to draw from right to left without using a transformation. These
nodes will will answer false
and implement right-to-left
orientation without using the automatic transformation.
usesMirroring
in class Node
public final void setText(String value)
public final String getText()
public final StringProperty textProperty()
getText()
,
setText(String)
public final void setX(double value)
public final double getX()
public final DoubleProperty xProperty()
getX()
,
setX(double)
public final void setY(double value)
public final double getY()
public final DoubleProperty yProperty()
getY()
,
setY(double)
public final void setFont(Font value)
public final Font getFont()
public final ObjectProperty<Font> fontProperty()
getFont()
,
setFont(Font)
public final void setTextOrigin(VPos value)
VPos.BASELINE
and
VPos.TOP
define the origin of the top row while
VPos.BOTTOM
defines the origin of the bottom row.public final VPos getTextOrigin()
VPos.BASELINE
and
VPos.TOP
define the origin of the top row while
VPos.BOTTOM
defines the origin of the bottom row.public final ObjectProperty<VPos> textOriginProperty()
VPos.BASELINE
and
VPos.TOP
define the origin of the top row while
VPos.BOTTOM
defines the origin of the bottom row.getTextOrigin()
,
setTextOrigin(VPos)
public final void setBoundsType(TextBoundsType value)
TextBoundsType
for more information.public final TextBoundsType getBoundsType()
TextBoundsType
for more information.public final ObjectProperty<TextBoundsType> boundsTypeProperty()
TextBoundsType
for more information.getBoundsType()
,
setBoundsType(TextBoundsType)
public final void setWrappingWidth(double value)
> 0
text will be line wrapped as needed
to satisfy this constraint.public final double getWrappingWidth()
> 0
text will be line wrapped as needed
to satisfy this constraint.public final DoubleProperty wrappingWidthProperty()
> 0
text will be line wrapped as needed
to satisfy this constraint.getWrappingWidth()
,
setWrappingWidth(double)
public final void setUnderline(boolean value)
public final boolean isUnderline()
public final BooleanProperty underlineProperty()
isUnderline()
,
setUnderline(boolean)
public final void setStrikethrough(boolean value)
public final boolean isStrikethrough()
public final BooleanProperty strikethroughProperty()
isStrikethrough()
,
setStrikethrough(boolean)
public final void setTextAlignment(TextAlignment value)
public final TextAlignment getTextAlignment()
public final ObjectProperty<TextAlignment> textAlignmentProperty()
getTextAlignment()
,
setTextAlignment(TextAlignment)
public final void setLineSpacing(double spacing)
public final double getLineSpacing()
public final DoubleProperty lineSpacingProperty()
getLineSpacing()
,
setLineSpacing(double)
public final double getBaselineOffset()
getBaselineOffset
in class Node
Node.BASELINE_OFFSET_SAME_AS_HEIGHT
otherwisepublic final ReadOnlyDoubleProperty baselineOffsetProperty()
getBaselineOffset()
public final void setFontSmoothingType(FontSmoothingType value)
public final FontSmoothingType getFontSmoothingType()
public final ObjectProperty<FontSmoothingType> fontSmoothingTypeProperty()
getFontSmoothingType()
,
setFontSmoothingType(FontSmoothingType)
public static List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
public List<CssMetaData<? extends Styleable,?>> getCssMetaData()
Node.getClassCssMetaData()
so that
a Node's CssMetaData can be accessed without the need for reflection.getCssMetaData
in interface Styleable
getCssMetaData
in class Shape
public String toString()
Text
object.public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)
Node
This method is commonly overridden by subclasses to implement
attributes that are required for a specific role.
If a particular attribute is not handled, the super class implementation
must be called.
queryAccessibleAttribute
in class Node
attribute
- the requested attributeparameters
- optional list of parametersAccessibleAttribute
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 2008, 2017, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.