public class TextFlow
extends Pane
Text
nodes in a single text flow.
The TextFlow uses the text and the font of each Text
node inside of it
plus it 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 Text
node can differ from the logical location
due to bidi reordering.
Any other Node, rather than Text, will be treated as 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 of a TextFlow some 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
is set to false
when it is laid out by the
TextFlow. This happens because the content of a single Text
node can
divided and placed in the different locations on 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
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 childrens' bounds may extend outside its own bounds if a child's pref size is larger than the space textflow has to allocate for it.
Type | Property and Description |
---|---|
DoubleProperty |
lineSpacing
Defines the vertical space in pixel between lines.
|
<any> |
textAlignment
Defines horizontal text alignment.
|
Modifier and Type | Class and Description |
---|---|
private static class |
TextFlow.EmbeddedSpan |
private static class |
TextFlow.StyleableProperties
*
Stylesheet Handling *
*
|
Modifier and Type | Field and Description |
---|---|
private boolean |
inLayout |
private TextLayout |
layout |
private DoubleProperty |
lineSpacing
Defines the vertical space in pixel between lines.
|
private boolean |
needsContent |
private <any> |
textAlignment
Defines horizontal text alignment.
|
Constructor and Description |
---|
TextFlow()
Creates an empty TextFlow layout.
|
TextFlow(Node... children)
Creates a TextFlow layout with the given children.
|
Modifier and Type | Method and Description |
---|---|
(package private) static double |
boundedSize(double min,
double pref,
double max) |
PathElement[] |
caretShape(int charIndex,
boolean leading)
Returns shape of caret in local coordinates.
|
private void |
checkOrientation() |
(package private) double |
computeChildPrefAreaHeight(Node child,
Insets margin) |
(package private) double |
computeChildPrefAreaHeight(Node child,
Insets margin,
double width) |
(package private) double |
computeChildPrefAreaWidth(Node child,
Insets margin) |
(package private) double |
computeChildPrefAreaWidth(Node child,
Insets margin,
double height) |
protected double |
computeMinHeight(double width) |
protected double |
computePrefHeight(double width) |
protected double |
computePrefWidth(double height) |
double |
getBaselineOffset() |
static java.util.List<<any>> |
getClassCssMetaData() |
Orientation |
getContentBias() |
java.util.List<<any>> |
getCssMetaData() |
double |
getLineSpacing()
Gets the value of the property lineSpacing.
|
private PathElement[] |
getRange(int start,
int end,
int type) |
TextAlignment |
getTextAlignment()
Gets the value of the property textAlignment.
|
(package private) TextLayout |
getTextLayout() |
HitInfo |
hitTest(javafx.geometry.Point2D point)
Maps local point to index in the content.
|
protected void |
layoutChildren() |
DoubleProperty |
lineSpacingProperty()
Defines the vertical space in pixel between lines.
|
java.lang.Object |
queryAccessibleAttribute(AccessibleAttribute attribute,
java.lang.Object... parameters) |
PathElement[] |
rangeShape(int start,
int end)
Returns shape for the range of the text in local coordinates.
|
void |
requestLayout() |
void |
setLineSpacing(double spacing)
Sets the value of the property lineSpacing.
|
void |
setTextAlignment(TextAlignment value)
Sets the value of the property textAlignment.
|
protected void |
setWidth(double value) |
private static double |
snapSpace(double value,
boolean snapToPixel) |
<any> |
textAlignmentProperty()
Defines horizontal text alignment.
|
boolean |
usesMirroring() |
public final <any> textAlignmentProperty
public final DoubleProperty lineSpacingProperty
getLineSpacing()
,
setLineSpacing(double)
private TextLayout layout
private boolean needsContent
private boolean inLayout
private <any> textAlignment
private DoubleProperty lineSpacing
public TextFlow()
public TextFlow(Node... children)
children
- children.private void checkOrientation()
public final HitInfo hitTest(javafx.geometry.Point2D point)
point
- the specified point to be testedHitInfo
representing the character index foundpublic PathElement[] caretShape(int charIndex, boolean leading)
charIndex
- the character index for the caretleading
- whether the caret is biased on the leading edge of the characterPathElement
which can be used to create a Shape
public final PathElement[] rangeShape(int start, int end)
start
- the beginning character index for the rangeend
- the end character index (non-inclusive) for the rangePathElement
which can be used to create a Shape
public boolean usesMirroring()
protected void setWidth(double value)
protected double computePrefWidth(double height)
protected double computePrefHeight(double width)
protected double computeMinHeight(double width)
public void requestLayout()
public Orientation getContentBias()
protected void layoutChildren()
private PathElement[] getRange(int start, int end, int type)
TextLayout getTextLayout()
public final void setTextAlignment(TextAlignment value)
public final TextAlignment getTextAlignment()
public final <any> textAlignmentProperty()
public final void setLineSpacing(double spacing)
public final double getLineSpacing()
public final DoubleProperty lineSpacingProperty()
getLineSpacing()
,
setLineSpacing(double)
public final double getBaselineOffset()
public static java.util.List<<any>> getClassCssMetaData()
public java.util.List<<any>> getCssMetaData()
private static double snapSpace(double value, boolean snapToPixel)
static double boundedSize(double min, double pref, double max)
double computeChildPrefAreaWidth(Node child, Insets margin)
double computeChildPrefAreaWidth(Node child, Insets margin, double height)
double computeChildPrefAreaHeight(Node child, Insets margin)
double computeChildPrefAreaHeight(Node child, Insets margin, double width)
public java.lang.Object queryAccessibleAttribute(AccessibleAttribute attribute, java.lang.Object... parameters)