Class TextFlow
- All Implemented Interfaces:
Styleable
,EventTarget
Text
nodes in a single text flow.
TextFlow
uses the text and the font of each Text
node inside of it,
plus its own width and text alignment to determine the location for each child.
A single Text
node can span over several lines due to wrapping, and
the visual location of the Text
node can differ from the logical location
due to bidi reordering.
Any Node
other than Text
will be treated as an embedded object in the
text layout. It will be inserted in the content using its preferred width,
height, and baseline offset.
When a Text
node is inside a TextFlow
, some of its properties are ignored.
For example, the x
and y
properties of the Text
node are ignored since
the location of the node is determined by the parent. Likewise, the wrapping
width in the Text
node is ignored since the width used for wrapping
is the TextFlow
's width. The value of the pickOnBounds
property
of a Text
node is set to false
when it is laid out by the
TextFlow
. This happens because the content of a single Text
node can be
split and placed in different locations in the TextFlow
(usually due to
line breaking and bidi reordering).
The wrapping width of the layout is determined by the region's current width.
It can be specified by the application by setting the TextFlow
's preferred
width. If no wrapping is desired, the application can either set the preferred
with to Double.MAX_VALUE
or
Region.USE_COMPUTED_SIZE
.
Paragraphs are separated by '\n'
present in any Text
child.
Example of a TextFlow:
Text text1 = new Text("Big italic red text");
text1.setFill(Color.RED);
text1.setFont(Font.font("Helvetica", FontPosture.ITALIC, 40));
Text text2 = new Text(" little bold blue text");
text2.setFill(Color.BLUE);
text2.setFont(Font.font("Helvetica", FontWeight.BOLD, 10));
TextFlow textFlow = new TextFlow(text1, text2);
TextFlow
lays out each managed child regardless of the child's visible property value;
unmanaged children are ignored for all layout calculations.
TextFlow
may be styled with backgrounds and borders using CSS. See its
Region
superclass for details.
Resizable Range
A TextFlow
's parent will resize the TextFlow
within the TextFlow
's range
during layout. By default, the TextFlow
computes this range based on its content
as outlined in the tables below.
width | height | |
---|---|---|
minimum | left/right insets | top/bottom insets plus the height of the text content |
preferred | left/right insets plus the width of the text content | top/bottom insets plus the height of the text content |
maximum | Double.MAX_VALUE | Double.MAX_VALUE |
A TextFlow
's unbounded maximum width and height are an indication to the parent that
it may be resized beyond its preferred size to fill whatever space is assigned to it.
TextFlow
provides properties for setting the size range directly. These
properties default to the sentinel value Region.USE_COMPUTED_SIZE
, however the
application may set them to other values as needed:
textflow.setMaxWidth(500);
Applications may restore the computed values by setting these properties back
to Region.USE_COMPUTED_SIZE
.
TextFlow
does not clip its content by default, so it is possible that children's
bounds may extend outside of its own bounds if a child's preferred size is larger than
the space the TextFlow
has to allocate for it.
- Since:
- JavaFX 8.0
-
Property Summary
PropertiesTypePropertyDescriptionfinal DoubleProperty
Defines the vertical space in pixel between lines.final IntegerProperty
The size of a tab stop in spaces.final ObjectProperty
<TabStopPolicy> Determines the tab stop positions within thisTextFlow
.final ObjectProperty
<TextAlignment> Defines horizontal text alignment.Properties declared in class javafx.scene.layout.Region
background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width
Properties declared in class javafx.scene.Parent
needsLayout
Properties declared in class javafx.scene.Node
accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, focusVisible, focusWithin, 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, viewOrder, visible
-
Field Summary
Fields declared in class javafx.scene.layout.Region
USE_COMPUTED_SIZE, USE_PREF_SIZE
Fields declared in class javafx.scene.Node
BASELINE_OFFSET_SAME_AS_HEIGHT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncaretShape
(int charIndex, boolean leading) Deprecated.final double
Calculates the baseline offset based on the first managed child.getCaretShape
(int charIndex, boolean leading) Returns shape of caret in local coordinates.static List
<CssMetaData<? extends Styleable, ?>> Gets theCssMetaData
associated with this class, which may include theCssMetaData
of its superclasses.final HitInfo
getHitInfo
(Point2D point) Maps local point toHitInfo
in the content.final LayoutInfo
Returns a copy of the of the text layout geometry for this node.final double
Gets the value of thelineSpacing
property.final PathElement[]
getRangeShape
(int start, int end, boolean includeLineSpacing) Returns shape for the range of the text in local coordinates.final PathElement[]
getStrikeThroughShape
(int start, int end) Returns the shape for the strike-through in local coordinates.final int
Gets the value of thetabSize
property.final TabStopPolicy
Gets the value of thetabStopPolicy
property.final TextAlignment
Gets the value of thetextAlignment
property.final PathElement[]
getUnderlineShape
(int start, int end) Returns the shape for the underline in local coordinates.final HitInfo
Deprecated.replaced bygetHitInfo(javafx.geometry.Point2D)
final DoubleProperty
Defines the vertical space in pixel between lines.final PathElement[]
rangeShape
(int start, int end) Deprecated.replaced bygetRangeShape(int, int, boolean)
final void
setLineSpacing
(double spacing) Sets the value of thelineSpacing
property.final void
setTabSize
(int spaces) Sets the value of thetabSize
property.final void
setTabStopPolicy
(TabStopPolicy policy) Sets the value of thetabStopPolicy
property.final void
setTextAlignment
(TextAlignment value) Sets the value of thetextAlignment
property.final IntegerProperty
The size of a tab stop in spaces.final ObjectProperty
<TabStopPolicy> Determines the tab stop positions within thisTextFlow
.final ObjectProperty
<TextAlignment> Defines horizontal text alignment.final PathElement[]
underlineShape
(int start, int end) Deprecated.replaced bygetUnderlineShape(int, int)
Methods declared in class javafx.scene.layout.Pane
getChildren
Methods declared in class javafx.scene.layout.Region
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, getBackground, getBorder, getCssMetaData, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isResizable, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty
Methods declared in class javafx.scene.Parent
getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, layoutChildren, needsLayoutProperty, requestLayout, requestParentLayout, setNeedsLayout, updateBounds
Methods declared in class javafx.scene.Node
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, focusVisibleProperty, focusWithinProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInitialFocusTraversable, 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, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isFocusVisible, isFocusWithin, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, 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, 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, pressedProperty, pseudoClassStateChanged, queryAccessibleAttribute, relocate, removeEventFilter, removeEventHandler, requestFocus, requestFocusTraversal, 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, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods declared in interface javafx.css.Styleable
getStyleableNode
-
Property Details
-
textAlignment
Defines horizontal text alignment.- Default value:
- TextAlignment.LEFT
- See Also:
-
lineSpacing
Defines the vertical space in pixel between lines.- Default value:
- 0
- Since:
- JavaFX 8.0
- See Also:
-
tabSize
The size of a tab stop in spaces. Values less than 1 are treated as 1. This value overrides thetabSize
of containedText
nodes.Note that this method should not be used to control the tab placement when multiple
Text
nodes with different fonts are contained within thisTextFlow
. In this case,setTabStopPolicy(TabStopPolicy)
should be used instead.- Default value:
- 8
- Since:
- 14
- See Also:
-
tabStopPolicy
Determines the tab stop positions within thisTextFlow
.A non-null
TabStopPolicy
overrides values set bysetTabSize(int)
, as well as any values set byText.setTabSize(int)
in individualText
instances within thisTextFlow
.- Default value:
- null
- Since:
- 25
- See Also:
-
-
Constructor Details
-
TextFlow
public TextFlow()Creates an empty TextFlow layout. -
TextFlow
Creates a TextFlow layout with the given children.- Parameters:
children
- children.
-
-
Method Details
-
hitTest
Deprecated.replaced bygetHitInfo(javafx.geometry.Point2D)
Maps local point toHitInfo
in the content.NOTE: this method does not take border or padding into account.
- Parameters:
point
- the specified point to be tested- Returns:
- a
HitInfo
representing the character index found - Since:
- 9
-
getHitInfo
-
caretShape
Deprecated.replaced bygetCaretShape(int, boolean)
Returns shape of caret in local coordinates.NOTE: this method does not take border or padding into account.
- Parameters:
charIndex
- the character index for the caretleading
- whether the caret is biased on the leading edge of the character- Returns:
- an array of
PathElement
which can be used to create aShape
- Since:
- 9
-
getCaretShape
Returns shape of caret in local coordinates.- Parameters:
charIndex
- the character index for the caretleading
- whether the caret is biased on the leading edge of the character- Returns:
- an array of
PathElement
which can be used to create aShape
- Since:
- 25
-
rangeShape
Deprecated.replaced bygetRangeShape(int, int, boolean)
Returns shape for the range of the text in local coordinates.NOTES:
- this method does not take border or padding into account
- the shapes returned do not include line spacing
- Parameters:
start
- the beginning character index for the rangeend
- the end character index (non-inclusive) for the range- Returns:
- an array of
PathElement
which can be used to create aShape
- Since:
- 9
-
getRangeShape
Returns shape for the range of the text in local coordinates.- Parameters:
start
- the beginning character index for the rangeend
- the end character index (non-inclusive) for the rangeincludeLineSpacing
- determines whether the result includes the line spacing- Returns:
- an array of
PathElement
which can be used to create aShape
- Since:
- 25
- See Also:
-
underlineShape
Deprecated.replaced bygetUnderlineShape(int, int)
Returns the shape for the underline in local coordinates.NOTE: this method does not take border or padding into account.
- Parameters:
start
- the beginning character index for the rangeend
- the end character index (non-inclusive) for the range- Returns:
- an array of
PathElement
which can be used to create aShape
- Since:
- 21
-
getUnderlineShape
Returns the shape for the underline in local coordinates.- Parameters:
start
- the beginning character index for the rangeend
- the end character index (non-inclusive) for the range- Returns:
- an array of
PathElement
which can be used to create aShape
- Since:
- 25
- See Also:
-
getStrikeThroughShape
Returns the shape for the strike-through in local coordinates.- Parameters:
start
- the beginning character index for the rangeend
- the end character index (non-inclusive) for the range- Returns:
- an array of
PathElement
which can be used to create aShape
- Since:
- 25
- See Also:
-
setTextAlignment
Sets the value of thetextAlignment
property.- Property description:
- Defines horizontal text alignment.
- Default value:
- TextAlignment.LEFT
- Parameters:
value
- the value for thetextAlignment
property- See Also:
-
getTextAlignment
Gets the value of thetextAlignment
property.- Property description:
- Defines horizontal text alignment.
- Default value:
- TextAlignment.LEFT
- Returns:
- the value of the
textAlignment
property - See Also:
-
textAlignmentProperty
Defines horizontal text alignment.- Default value:
- TextAlignment.LEFT
- Returns:
- the
textAlignment
property - See Also:
-
setLineSpacing
public final void setLineSpacing(double spacing) Sets the value of thelineSpacing
property.- Property description:
- Defines the vertical space in pixel between lines.
- Default value:
- 0
- Parameters:
spacing
- the value for thelineSpacing
property- Since:
- JavaFX 8.0
- See Also:
-
getLineSpacing
public final double getLineSpacing()Gets the value of thelineSpacing
property.- Property description:
- Defines the vertical space in pixel between lines.
- Default value:
- 0
- Returns:
- the value of the
lineSpacing
property - Since:
- JavaFX 8.0
- See Also:
-
lineSpacingProperty
Defines the vertical space in pixel between lines.- Default value:
- 0
- Returns:
- the
lineSpacing
property - Since:
- JavaFX 8.0
- See Also:
-
tabSizeProperty
The size of a tab stop in spaces. Values less than 1 are treated as 1. This value overrides thetabSize
of containedText
nodes.Note that this method should not be used to control the tab placement when multiple
Text
nodes with different fonts are contained within thisTextFlow
. In this case,setTabStopPolicy(TabStopPolicy)
should be used instead.- Default value:
- 8
- Returns:
- the
tabSize
property - Since:
- 14
- See Also:
-
getTabSize
public final int getTabSize()Gets the value of thetabSize
property.- Property description:
- The size of a tab stop in spaces.
Values less than 1 are treated as 1. This value overrides the
tabSize
of containedText
nodes.Note that this method should not be used to control the tab placement when multiple
Text
nodes with different fonts are contained within thisTextFlow
. In this case,setTabStopPolicy(TabStopPolicy)
should be used instead. - Default value:
- 8
- Returns:
- the value of the
tabSize
property - Since:
- 14
- See Also:
-
setTabSize
public final void setTabSize(int spaces) Sets the value of thetabSize
property.- Property description:
- The size of a tab stop in spaces.
Values less than 1 are treated as 1. This value overrides the
tabSize
of containedText
nodes.Note that this method should not be used to control the tab placement when multiple
Text
nodes with different fonts are contained within thisTextFlow
. In this case,setTabStopPolicy(TabStopPolicy)
should be used instead. - Default value:
- 8
- Parameters:
spaces
- the value for thetabSize
property- Since:
- 14
- See Also:
-
tabStopPolicyProperty
Determines the tab stop positions within thisTextFlow
.A non-null
TabStopPolicy
overrides values set bysetTabSize(int)
, as well as any values set byText.setTabSize(int)
in individualText
instances within thisTextFlow
.- Default value:
- null
- Returns:
- the
tabStopPolicy
property - Since:
- 25
- See Also:
-
getTabStopPolicy
Gets the value of thetabStopPolicy
property.- Property description:
- Determines the tab stop positions within this
TextFlow
.A non-null
TabStopPolicy
overrides values set bysetTabSize(int)
, as well as any values set byText.setTabSize(int)
in individualText
instances within thisTextFlow
. - Default value:
- null
- Returns:
- the value of the
tabStopPolicy
property - Since:
- 25
- See Also:
-
setTabStopPolicy
Sets the value of thetabStopPolicy
property.- Property description:
- Determines the tab stop positions within this
TextFlow
.A non-null
TabStopPolicy
overrides values set bysetTabSize(int)
, as well as any values set byText.setTabSize(int)
in individualText
instances within thisTextFlow
. - Default value:
- null
- Parameters:
policy
- the value for thetabStopPolicy
property- Since:
- 25
- See Also:
-
getBaselineOffset
public final double getBaselineOffset()Description copied from class:Parent
Calculates the baseline offset based on the first managed child. If there is no such child, returnsNode.getBaselineOffset()
.- Overrides:
getBaselineOffset
in classParent
- Returns:
- baseline offset
-
getClassCssMetaData
Gets theCssMetaData
associated with this class, which may include theCssMetaData
of its superclasses.- Returns:
- the
CssMetaData
-
getLayoutInfo
Returns a copy of the of the text layout geometry for this node. This copy is a snapshot of the text layout at the time the method is called.While there is no general guarantee that successive invocations of this method return the same instance, it is safe to either cache this object or call this method each time, since the information obtained from this lightweight object remains valid until the next layout cycle.
- Returns:
- a copy of the layout information
- Since:
- 25
-
getCaretShape(int, boolean)