Top Description Inners Fields Constructors Methods
javafx.scene.text

public Class TextFlow

extends Pane
Class Inheritance
Imports
java.util.ArrayList, .Collections, .List, javafx.beans.property.DoubleProperty, .IntegerProperty, .ObjectProperty, javafx.css.CssMetaData, .Styleable, .StyleableDoubleProperty, .StyleableIntegerProperty, .StyleableObjectProperty, .StyleableProperty, javafx.css.converter.EnumConverter, .SizeConverter, javafx.geometry.HPos, .Insets, .NodeOrientation, .Orientation, .VPos, javafx.scene.AccessibleAttribute, .AccessibleRole, .Node, javafx.scene.layout.Pane, javafx.scene.shape.PathElement, com.sun.javafx.geom.BaseBounds, .Point2D, .RectBounds, com.sun.javafx.scene.text.GlyphList, .TextFlowHelper, .TextLayout, .TextLayoutFactory, .TextSpan, com.sun.javafx.tk.Toolkit

A specialized layout for rich text. It can be used to lay out several 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.

TextFlow Resize Table
widthheight
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_VALUEDouble.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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private boolean
private TextLayout
private DoubleProperty
lineSpacing

Defines the vertical space in pixel between lines.

private boolean
private IntegerProperty
tabSize

The size of a tab stop in spaces.

private ObjectProperty<TextAlignment>
textAlignment

Defines horizontal text alignment.

Constructor Summary

AccessConstructor and Description
public
TextFlow()

Creates an empty TextFlow layout.

public
TextFlow(Node...
children.
children
)

Creates a TextFlow layout with the given children.

Method Summary

Modifier and TypeMethod and Description
pack-priv static double
boundedSize(double
The minimum bound
min
,
double
The value to be clamped between the min and max
pref
,
double
the maximum bound
max
)

Hides javafx.scene.layout.Region.boundedSize.

Computes the value based on the given min and max values.

public PathElement[]

Returns:

an array of PathElement which can be used to create a Shape
caretShape
(int
the character index for the caret
charIndex
,
boolean
whether the caret is biased on the leading edge of the character
leading
)

Returns shape of caret in local coordinates.

private void
pack-priv double
pack-priv double
computeChildPrefAreaHeight(Node child, Insets margin, double width)

pack-priv double
pack-priv double
computeChildPrefAreaWidth(Node child, Insets margin, double height)

protected double
computeMinHeight(double
the width that should be used if min height depends on it
width
)

Overrides javafx.scene.layout.Region.computeMinHeight.

Computes the minimum height of this region.

protected double
computePrefHeight(double
the width that should be used if preferred height depends on it
width
)

Overrides javafx.scene.layout.Region.computePrefHeight.

Computes the preferred height of this region for the given width; Region subclasses should override this method to return an appropriate value based on their content and layout strategy.

protected double
computePrefWidth(double
the height that should be used if preferred width depends on it
height
)

Overrides javafx.scene.layout.Region.computePrefWidth.

Computes the preferred width of this region for the given height.

public final double
getBaselineOffset()

Overrides javafx.scene.Parent.getBaselineOffset.

Calculates the baseline offset based on the first managed child.

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

Returns:

the CssMetaData
getClassCssMetaData
()

Hides javafx.scene.layout.Region.getClassCssMetaData.

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

public Orientation
getContentBias()

Overrides javafx.scene.Node.getContentBias.

Returns the orientation of a node's resizing bias for layout purposes.

public List<CssMetaData<? extends Styleable, ?>>
getCssMetaData()

Overrides javafx.scene.layout.Region.getCssMetaData.

Implements javafx.css.Styleable.getCssMetaData.

This method should delegate to Node#getClassCssMetaData() so that a Node's CssMetaData can be accessed without the need for reflection.

public final double
private PathElement[]
getRange(int start, int end, int type)

public final int
public final TextAlignment
pack-priv TextLayout
public final HitInfo

Returns:

a HitInfo representing the character index found
hitTest
(Point2D
the specified point to be tested
point
)

Maps local point to HitInfo in the content.

private static void
protected void
layoutChildren()

Overrides javafx.scene.Parent.layoutChildren.

Invoked during the layout pass to layout the children in this Parent.

public final DoubleProperty
public Object
queryAccessibleAttribute(AccessibleAttribute
the requested attribute
attribute
,
Object...
optional list of parameters
parameters
)

Overrides javafx.scene.Parent.queryAccessibleAttribute.

This method is called by the assistive technology to request the value for an attribute.

public final PathElement[]

Returns:

an array of PathElement which can be used to create a Shape
rangeShape
(int
the beginning character index for the range
start
,
int
the end character index (non-inclusive) for the range
end
)

Returns shape for the range of the text in local coordinates.

public void
requestLayout()

Overrides javafx.scene.Parent.requestLayout.

Requests a layout pass to be performed before the next scene is rendered.

public final void
setLineSpacing(double spacing)

public final void
setTabSize(int spaces)

public final void
protected void
public final IntegerProperty
public final ObjectProperty<TextAlignment>
public final PathElement[]

Returns:

an array of PathElement which can be used to create a Shape
underlineShape
(int
the beginning character index for the range
start
,
int
the end character index (non-inclusive) for the range
end
)

Returns the shape for the underline in local coordinates.

public boolean
usesMirroring()

Overrides javafx.scene.Node.usesMirroring.

Determines whether a node should be mirrored when node orientation is right-to-left.

Inherited from javafx.scene.layout.Pane:
getChildren

Field Detail

inLayoutback to summary
private boolean inLayout
layoutback to summary
private TextLayout layout
lineSpacingback to summary
private DoubleProperty lineSpacing

Defines the vertical space in pixel between lines.

Default Value
0
Since
JavaFX 8.0
needsContentback to summary
private boolean needsContent
tabSizeback to summary
private IntegerProperty tabSize

The size of a tab stop in spaces. Values less than 1 are treated as 1. This value overrides the tabSize of contained Text nodes.

Default Value
8
Since
14
textAlignmentback to summary
private ObjectProperty<TextAlignment> textAlignment

Defines horizontal text alignment.

Default Value
TextAlignment.LEFT

Constructor Detail

TextFlowback to summary
public TextFlow()

Creates an empty TextFlow layout.

TextFlowback to summary
public TextFlow(Node... children)

Creates a TextFlow layout with the given children.

Parameters
children:Node[]

children.

Method Detail

boundedSizeback to summary
pack-priv static double boundedSize(double min, double pref, double max)

Hides javafx.scene.layout.Region.boundedSize.

Doc from javafx.scene.layout.Region.boundedSize.

Computes the value based on the given min and max values. We encode in this method the logic surrounding various edge cases, such as when the min is specified as greater than the max, or the max less than the min, or a pref value that exceeds either the max or min in their extremes.

If the min is greater than the max, then we want to make sure the returned value is the min. In other words, in such a case, the min becomes the only acceptable return value.

If the min and max values are well ordered, and the pref is less than the min then the min is returned. Likewise, if the values are well ordered and the pref is greater than the max, then the max is returned. If the pref lies between the min and the max, then the pref is returned.

Parameters
min:double

The minimum bound

pref:double

The value to be clamped between the min and max

max:double

the maximum bound

Returns:double

the size bounded by min, pref, and max.

caretShapeback to summary
public PathElement[] caretShape(int charIndex, boolean leading)

Returns shape of caret in local coordinates.

Parameters
charIndex:int

the character index for the caret

leading:boolean

whether the caret is biased on the leading edge of the character

Returns:PathElement[]

an array of PathElement which can be used to create a Shape

Since
9
checkOrientationback to summary
private void checkOrientation()
computeChildPrefAreaHeightback to summary
pack-priv double computeChildPrefAreaHeight(Node child, Insets margin)

Hides javafx.scene.layout.Region.computeChildPrefAreaHeight.

computeChildPrefAreaHeightback to summary
pack-priv double computeChildPrefAreaHeight(Node child, Insets margin, double width)
computeChildPrefAreaWidthback to summary
pack-priv double computeChildPrefAreaWidth(Node child, Insets margin)

Hides javafx.scene.layout.Region.computeChildPrefAreaWidth.

computeChildPrefAreaWidthback to summary
pack-priv double computeChildPrefAreaWidth(Node child, Insets margin, double height)
computeMinHeightback to summary
protected double computeMinHeight(double width)

Overrides javafx.scene.layout.Region.computeMinHeight.

Doc from javafx.scene.layout.Region.computeMinHeight.

Computes the minimum height of this region. Returns the sum of the top and bottom insets by default. Region subclasses should override this method to return an appropriate value based on their content and layout strategy. If the subclass doesn't have a HORIZONTAL content bias, then the width parameter can be ignored.

Parameters
width:double

Doc from javafx.scene.Parent.computeMinHeight.

the width that should be used if min height depends on it

Returns:double

the computed minimum height for this region

Annotations
@Override
computePrefHeightback to summary
protected double computePrefHeight(double width)

Overrides javafx.scene.layout.Region.computePrefHeight.

Doc from javafx.scene.layout.Region.computePrefHeight.

Computes the preferred height of this region for the given width; Region subclasses should override this method to return an appropriate value based on their content and layout strategy. If the subclass doesn't have a HORIZONTAL content bias, then the width parameter can be ignored.

Parameters
width:double

Doc from javafx.scene.Parent.computePrefHeight.

the width that should be used if preferred height depends on it

Returns:double

the computed preferred height for this region

Annotations
@Override
computePrefWidthback to summary
protected double computePrefWidth(double height)

Overrides javafx.scene.layout.Region.computePrefWidth.

Doc from javafx.scene.layout.Region.computePrefWidth.

Computes the preferred width of this region for the given height. Region subclasses should override this method to return an appropriate value based on their content and layout strategy. If the subclass doesn't have a VERTICAL content bias, then the height parameter can be ignored.

Parameters
height:double

Doc from javafx.scene.Parent.computePrefWidth.

the height that should be used if preferred width depends on it

Returns:double

the computed preferred width for this region

Annotations
@Override
getBaselineOffsetback to summary
public final double getBaselineOffset()

Overrides javafx.scene.Parent.getBaselineOffset.

Doc from javafx.scene.Parent.getBaselineOffset.

Calculates the baseline offset based on the first managed child. If there is no such child, returns Node#getBaselineOffset().

Returns:double

baseline offset

Annotations
@Override
getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides javafx.scene.layout.Region.getClassCssMetaData.

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

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

the CssMetaData

getContentBiasback to summary
public Orientation getContentBias()

Overrides javafx.scene.Node.getContentBias.

Doc from javafx.scene.Node.getContentBias.

Returns the orientation of a node's resizing bias for layout purposes. If the node type has no bias, returns null. If the node is resizable and it's height depends on its width, returns HORIZONTAL, else if its width depends on its height, returns VERTICAL.

Resizable subclasses should override this method to return an appropriate value.

Returns:Orientation

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

Annotations
@Override
getCssMetaDataback to summary
public List<CssMetaData<? extends Styleable, ?>> getCssMetaData()

Overrides javafx.scene.layout.Region.getCssMetaData.

Implements javafx.css.Styleable.getCssMetaData.

Doc from javafx.scene.layout.Region.getCssMetaData.

This method should delegate to Node#getClassCssMetaData() so that a Node's CssMetaData can be accessed without the need for reflection.

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

Doc from javafx.scene.Node.getCssMetaData.

The CssMetaData associated with this node, which may include the CssMetaData of its superclasses.

Annotations
@Override
getLineSpacingback to summary
public final double getLineSpacing()
getRangeback to summary
private PathElement[] getRange(int start, int end, int type)
getTabSizeback to summary
public final int getTabSize()
getTextAlignmentback to summary
public final TextAlignment getTextAlignment()
getTextLayoutback to summary
pack-priv TextLayout getTextLayout()
hitTestback to summary
public final HitInfo hitTest(Point2D point)

Maps local point to HitInfo in the content.

Parameters
point:Point2D

the specified point to be tested

Returns:HitInfo

a HitInfo representing the character index found

Since
9
initAccessorback to summary
private static void initAccessor()
layoutChildrenback to summary
protected void layoutChildren()

Overrides javafx.scene.Parent.layoutChildren.

Doc from javafx.scene.Parent.layoutChildren.

Invoked during the layout pass to layout the children in this Parent. By default it will only set the size of managed, resizable content to their preferred sizes and does not do any node positioning.

Subclasses should override this function to layout content as needed.

Annotations
@Override
lineSpacingPropertyback to summary
public final DoubleProperty lineSpacingProperty()
queryAccessibleAttributeback to summary
public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)

Overrides javafx.scene.Parent.queryAccessibleAttribute.

Doc from javafx.scene.Parent.queryAccessibleAttribute.

This method is called by the assistive technology to request the value for an attribute.

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 superclass implementation must be called.

Parameters
attribute:AccessibleAttribute

Doc from javafx.scene.Node.queryAccessibleAttribute.

the requested attribute

parameters:Object[]

Doc from javafx.scene.Node.queryAccessibleAttribute.

optional list of parameters

Returns:Object

Doc from javafx.scene.Node.queryAccessibleAttribute.

the value for the requested attribute

Annotations
@Override
rangeShapeback to summary
public final PathElement[] rangeShape(int start, int end)

Returns shape for the range of the text in local coordinates.

Parameters
start:int

the beginning character index for the range

end:int

the end character index (non-inclusive) for the range

Returns:PathElement[]

an array of PathElement which can be used to create a Shape

Since
9
requestLayoutback to summary
public void requestLayout()

Overrides javafx.scene.Parent.requestLayout.

Doc from javafx.scene.Parent.requestLayout.

Requests a layout pass to be performed before the next scene is rendered. This is batched up asynchronously to happen once per "pulse", or frame of animation.

If this parent is either a layout root or unmanaged, then it will be added directly to the scene's dirty layout list, otherwise requestParentLayout will be invoked.

Annotations
@Override
setLineSpacingback to summary
public final void setLineSpacing(double spacing)
setTabSizeback to summary
public final void setTabSize(int spaces)
setTextAlignmentback to summary
public final void setTextAlignment(TextAlignment value)
setWidthback to summary
protected void setWidth(double value)

Overrides javafx.scene.layout.Region.setWidth.

Annotations
@Override
tabSizePropertyback to summary
public final IntegerProperty tabSizeProperty()
textAlignmentPropertyback to summary
public final ObjectProperty<TextAlignment> textAlignmentProperty()
underlineShapeback to summary
public final PathElement[] underlineShape(int start, int end)

Returns the shape for the underline in local coordinates.

Parameters
start:int

the beginning character index for the range

end:int

the end character index (non-inclusive) for the range

Returns:PathElement[]

an array of PathElement which can be used to create a Shape

Since
21
usesMirroringback to summary
public boolean usesMirroring()

Overrides javafx.scene.Node.usesMirroring.

Doc from javafx.scene.Node.usesMirroring.

Determines whether a node should be mirrored when node orientation is right-to-left.

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 answer false and implement right-to-left orientation without using the automatic transformation.

Returns:boolean

true if this Node should be mirrored

Annotations
@Override
javafx.scene.text back to summary

private Class TextFlow.EmbeddedSpan

extends Object
implements TextSpan
Class Inheritance
All Implemented Interfaces
com.sun.javafx.scene.text.TextSpan

Field Summary

Modifier and TypeField and Description
pack-priv RectBounds
pack-priv Node

Constructor Summary

AccessConstructor and Description
public
EmbeddedSpan(Node node, double baseline, double width, double height)

Method Summary

Modifier and TypeMethod and Description
public RectBounds
getBounds()

Implements com.sun.javafx.scene.text.TextSpan.getBounds.

The bounds for embedded object, only used the font returns null.

public Object
getFont()

Implements com.sun.javafx.scene.text.TextSpan.getFont.

The font for the span, if null the span is handled as embedded object.

public Node
public String
getText()

Implements com.sun.javafx.scene.text.TextSpan.getText.

The text for the span, can be empty but not null.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

boundsback to summary
pack-priv RectBounds bounds
nodeback to summary
pack-priv Node node

Constructor Detail

EmbeddedSpanback to summary
public EmbeddedSpan(Node node, double baseline, double width, double height)

Method Detail

getBoundsback to summary
public RectBounds getBounds()

Implements com.sun.javafx.scene.text.TextSpan.getBounds.

Doc from com.sun.javafx.scene.text.TextSpan.getBounds.

The bounds for embedded object, only used the font returns null. The text for a embedded object should be a single char ("" is recommended).

Annotations
@Override
getFontback to summary
public Object getFont()

Implements com.sun.javafx.scene.text.TextSpan.getFont.

Doc from com.sun.javafx.scene.text.TextSpan.getFont.

The font for the span, if null the span is handled as embedded object.

Annotations
@Override
getNodeback to summary
public Node getNode()
getTextback to summary
public String getText()

Implements com.sun.javafx.scene.text.TextSpan.getText.

Doc from com.sun.javafx.scene.text.TextSpan.getText.

The text for the span, can be empty but not null.

Annotations
@Override
javafx.scene.text back to summary

private Class TextFlow.StyleableProperties

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final CssMetaData<TextFlow, Number>
private static final List<CssMetaData<? extends Styleable, ?>>
private static final CssMetaData<TextFlow, Number>
private static final CssMetaData<TextFlow, TextAlignment>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LINE_SPACINGback to summary
private static final CssMetaData<TextFlow, Number> LINE_SPACING
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES
TAB_SIZEback to summary
private static final CssMetaData<TextFlow, Number> TAB_SIZE
TEXT_ALIGNMENTback to summary
private static final CssMetaData<TextFlow, TextAlignment> TEXT_ALIGNMENT

Constructor Detail

StyleablePropertiesback to summary
private StyleableProperties()