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..
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.
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.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private static class |
| Modifier and Type | Field 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 SimpleObjectProperty | tabStopPolicy
Determines the tab stop positions within this |
| private ObjectProperty | textAlignment
Defines horizontal text alignment. |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv static double | boundedSize(double min, double pref, double max)
Hides javafx. Computes the value based on the given min and max values. |
| public PathElement[] | Returns: an array ofPathElement which can be used to create a Shapethe character index for the caret charIndex, boolean whether the caret is biased on the leading edge of the character leading)
Deprecated
since 25. replaced by
getCaretShape(int, boolean)
Returns shape of caret in local coordinates. |
| private void | |
| pack-priv double | computeChildPrefAreaHeight(Node child, Insets margin)
Hides javafx.
|
| pack-priv double | |
| pack-priv double | computeChildPrefAreaWidth(Node child, Insets margin)
Hides javafx.
|
| pack-priv double | |
| protected double | computeMinHeight(double width)
Overrides javafx. Computes the minimum height of this region. |
| protected double | computePrefHeight(double width)
Overrides javafx. 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 height)
Overrides javafx. Computes the preferred width of this region for the given height. |
| public final double | getBaselineOffset()
Overrides javafx. Calculates the baseline offset based on the first managed child. |
| public PathElement[] | Returns: an array ofPathElement which can be used to create a Shapethe 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. |
| public static List | Returns: theCssMetaDataHides javafx. Gets the |
| public Orientation | getContentBias()
Overrides javafx. Returns the orientation of a node's resizing bias for layout purposes. |
| public List | getCssMetaData()
Overrides javafx. Implements javafx. This method should delegate to |
| public final HitInfo | Returns: aHitInfo representing the character index foundthe specified point to be tested point)Maps local point to |
| public final LayoutInfo | Returns: a copy of the layout informationReturns a copy of the of the text layout geometry for this node. |
| public final double | |
| private PathElement[] | |
| public final PathElement[] | Returns: an array ofPathElement which can be used to create a Shapethe beginning character index for the range start, int the end character index (non-inclusive) for the range end, boolean determines whether the result includes the line spacing includeLineSpacing)Returns shape for the range of the text in local coordinates. |
| public final PathElement[] | Returns: an array ofPathElement which can be used to create a Shapethe beginning character index for the range start, int the end character index (non-inclusive) for the range end)Returns the shape for the strike-through in local coordinates. |
| private TabAdvancePolicy | |
| public final int | |
| public final TabStopPolicy | |
| public final TextAlignment | |
| pack-priv TextLayout | |
| public final PathElement[] | Returns: an array ofPathElement which can be used to create a Shapethe 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 final HitInfo | Returns: aHitInfo representing the character index foundthe specified point to be tested point)
Deprecated
since 25. replaced by
getHitInfo(javafx.
Maps local point to |
| private static void | |
| protected void | layoutChildren()
Overrides javafx. Invoked during the layout pass to layout the children in this
|
| public final DoubleProperty | |
| public Object | queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)
Overrides javafx. This method is called by the assistive technology to request the value for an attribute. |
| public final PathElement[] | Returns: an array ofPathElement which can be used to create a Shapethe beginning character index for the range start, int the end character index (non-inclusive) for the range end)
Deprecated
since 25. replaced by
getRangeShape(int, int, boolean)
Returns shape for the range of the text in local coordinates. |
| public void | requestLayout()
Overrides javafx. Requests a layout pass to be performed before the next scene is rendered. |
| public final void | |
| public final void | |
| public final void | |
| public final void | |
| protected void | |
| public final IntegerProperty | |
| public final ObjectProperty | |
| public final ObjectProperty | |
| public final PathElement[] | Returns: an array ofPathElement which can be used to create a Shapethe beginning character index for the range start, int the end character index (non-inclusive) for the range end)
Deprecated
since 25. replaced by
getUnderlineShape(int, int)
Returns the shape for the underline in local coordinates. |
| public boolean | usesMirroring()
Overrides javafx. Determines whether a node should be mirrored when node orientation is right-to-left. |
| inLayout | back to summary |
|---|---|
| private boolean inLayout | |
| layout | back to summary |
|---|---|
| private TextLayout layout | |
| lineSpacing | back to summary |
|---|---|
| private DoubleProperty lineSpacing Defines the vertical space in pixel between lines.
| |
| needsContent | back to summary |
|---|---|
| private boolean needsContent | |
| tabSize | back 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
Note that this method should not be used to control the tab placement when multiple
| |
| tabStopPolicy | back to summary |
|---|---|
| private SimpleObjectProperty<TabStopPolicy> tabStopPolicy Determines the tab stop positions within this
A non-null
| |
| textAlignment | back to summary |
|---|---|
| private ObjectProperty<TextAlignment> textAlignment Defines horizontal text alignment.
| |
| TextFlow | back to summary |
|---|---|
| public TextFlow() Creates an empty TextFlow layout. | |
| TextFlow | back to summary |
|---|---|
| public TextFlow(Node... children) Creates a TextFlow layout with the given children.
| |
| boundedSize | back to summary |
|---|---|
| pack-priv static double boundedSize(double min, double pref, double max) Hides javafx. Doc from javafx. 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. | |
| caretShape | back to summary |
|---|---|
| public PathElement[] caretShape(int charIndex, boolean leading)
Returns shape of caret in local coordinates. Note this method does not take border or padding into account.
| |
| checkOrientation | back to summary |
|---|---|
| private void checkOrientation() | |
| computeChildPrefAreaHeight | back to summary |
|---|---|
| pack-priv double computeChildPrefAreaHeight(Node child, Insets margin) Hides javafx. | |
| computeChildPrefAreaHeight | back to summary |
|---|---|
| pack-priv double computeChildPrefAreaHeight(Node child, Insets margin, double width) | |
| computeChildPrefAreaWidth | back to summary |
|---|---|
| pack-priv double computeChildPrefAreaWidth(Node child, Insets margin) | |
| computeChildPrefAreaWidth | back to summary |
|---|---|
| pack-priv double computeChildPrefAreaWidth(Node child, Insets margin, double height) | |
| computeMinHeight | back to summary |
|---|---|
| protected double computeMinHeight(double width) Overrides javafx. Doc from javafx. 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.
| |
| computePrefHeight | back to summary |
|---|---|
| protected double computePrefHeight(double width) Overrides javafx. Doc from javafx. 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.
| |
| computePrefWidth | back to summary |
|---|---|
| protected double computePrefWidth(double height) Overrides javafx. Doc from javafx. 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.
| |
| getBaselineOffset | back to summary |
|---|---|
| public final double getBaselineOffset() Overrides javafx. Doc from javafx. Calculates the baseline offset based on the first managed child. If there
is no such child, returns
| |
| getCaretShape | back to summary |
|---|---|
| public PathElement[] getCaretShape(int charIndex, boolean leading) Returns shape of caret in local coordinates.
| |
| getClassCssMetaData | back to summary |
|---|---|
| public static List Hides javafx. Gets the
| |
| getContentBias | back to summary |
|---|---|
| public Orientation getContentBias() Overrides javafx. Doc from javafx. 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.
| |
| getCssMetaData | back to summary |
|---|---|
| public List Overrides javafx. Implements javafx. Doc from javafx. This method should delegate to
| |
| getHitInfo | back to summary |
|---|---|
| public final HitInfo getHitInfo(Point2D point) Maps local point to | |
| getLayoutInfo | back to summary |
|---|---|
| public final LayoutInfo 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.
| |
| getLineSpacing | back to summary |
|---|---|
| public final double getLineSpacing() | |
| getRange | back to summary |
|---|---|
| private PathElement[] getRange(int start, int end, int type, boolean accountForInsets, double lineSpacing) | |
| getRangeShape | back to summary |
|---|---|
| public final PathElement[] getRangeShape(int start, int end, boolean includeLineSpacing) Returns shape for the range of the text in local coordinates.
| |
| getStrikeThroughShape | back to summary |
|---|---|
| public final PathElement[] getStrikeThroughShape(int start, int end) Returns the shape for the strike-through in local coordinates.
| |
| getTabAdvancePolicy | back to summary |
|---|---|
| private TabAdvancePolicy getTabAdvancePolicy() | |
| getTabSize | back to summary |
|---|---|
| public final int getTabSize() | |
| getTabStopPolicy | back to summary |
|---|---|
| public final TabStopPolicy getTabStopPolicy() | |
| getTextAlignment | back to summary |
|---|---|
| public final TextAlignment getTextAlignment() | |
| getTextLayout | back to summary |
|---|---|
| pack-priv TextLayout getTextLayout() | |
| getUnderlineShape | back to summary |
|---|---|
| public final PathElement[] getUnderlineShape(int start, int end) Returns the shape for the underline in local coordinates.
| |
| hitTest | back to summary |
|---|---|
| public final HitInfo hitTest(Point2D point)
Maps local point to Note this method does not take border or padding into account.
| |
| initAccessor | back to summary |
|---|---|
| private static void initAccessor() | |
| layoutChildren | back to summary |
|---|---|
| protected void layoutChildren() Overrides javafx. Doc from javafx. Invoked during the layout pass to layout the children in this
Subclasses should override this function to layout content as needed.
| |
| lineSpacingProperty | back to summary |
|---|---|
| public final DoubleProperty lineSpacingProperty() | |
| queryAccessibleAttribute | back to summary |
|---|---|
| public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters) Overrides javafx. Doc from javafx. 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.
| |
| rangeShape | back to summary |
|---|---|
| public final PathElement[] rangeShape(int start, int end)
Returns shape for the range of the text in local coordinates. NOTES:
| |
| requestLayout | back to summary |
|---|---|
| public void requestLayout() Overrides javafx. Doc from javafx. 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.
| |
| setLineSpacing | back to summary |
|---|---|
| public final void setLineSpacing(double spacing) | |
| setTabSize | back to summary |
|---|---|
| public final void setTabSize(int spaces) | |
| setTabStopPolicy | back to summary |
|---|---|
| public final void setTabStopPolicy(TabStopPolicy policy) | |
| setTextAlignment | back to summary |
|---|---|
| public final void setTextAlignment(TextAlignment value) | |
| setWidth | back to summary |
|---|---|
| protected void setWidth(double value) Overrides javafx.
| |
| tabSizeProperty | back to summary |
|---|---|
| public final IntegerProperty tabSizeProperty() | |
| tabStopPolicyProperty | back to summary |
|---|---|
| public final ObjectProperty | |
| textAlignmentProperty | back to summary |
|---|---|
| public final ObjectProperty | |
| underlineShape | back to summary |
|---|---|
| public final PathElement[] underlineShape(int start, int end)
Returns the shape for the underline in local coordinates. Note this method does not take border or padding into account.
| |
| usesMirroring | back to summary |
|---|---|
| public boolean usesMirroring() Overrides javafx. Doc from javafx. 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
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv RectBounds | |
| pack-priv Node |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public RectBounds | getBounds()
Implements com. The bounds for embedded object, only used when the font returns null. |
| public Object | getFont()
Implements com. The font for the span, if null the span is handled as embedded object. |
| public Region | getLayoutRootRegion()
Implements com. Returns the |
| public Node | |
| public String | getText()
Implements com. The text for the span, can be empty but not null. |
| bounds | back to summary |
|---|---|
| pack-priv RectBounds bounds | |
| node | back to summary |
|---|---|
| pack-priv Node node | |
| EmbeddedSpan | back to summary |
|---|---|
| public EmbeddedSpan(Node node, double baseline, double width, double height) | |
| getBounds | back to summary |
|---|---|
| public RectBounds getBounds() Implements com. Doc from com. The bounds for embedded object, only used when the font returns null. The text for a embedded object should be a single char ("" is recommended).
| |
| getFont | back to summary |
|---|---|
| public Object getFont() Implements com. Doc from com. The font for the span, if null the span is handled as embedded object.
| |
| getLayoutRootRegion | back to summary |
|---|---|
| public Region getLayoutRootRegion() Implements com. Doc from com. Returns the
| |
| getNode | back to summary |
|---|---|
| public Node getNode() | |
| getText | back to summary |
|---|---|
| public String getText() Implements com. Doc from com. The text for the span, can be empty but not null.
| |
| Modifier and Type | Field and Description |
|---|---|
| private static final CssMetaData | |
| private static final List | |
| private static final CssMetaData | |
| private static final CssMetaData |
| Access | Constructor and Description |
|---|---|
| private |
| LINE_SPACING | back to summary |
|---|---|
| private static final CssMetaData<TextFlow, Number> LINE_SPACING | |
| STYLEABLES | back to summary |
|---|---|
| private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES | |
| TAB_SIZE | back to summary |
|---|---|
| private static final CssMetaData<TextFlow, Number> TAB_SIZE | |
| TEXT_ALIGNMENT | back to summary |
|---|---|
| private static final CssMetaData<TextFlow, TextAlignment> TEXT_ALIGNMENT | |
| StyleableProperties | back to summary |
|---|---|
| private StyleableProperties() | |