Class TextFlow

All Implemented Interfaces:
Styleable, EventTarget

public class TextFlow extends Pane
TextFlow is special layout designed to lay out rich text. It can be used to layout several Text nodes in a single text flow. The 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 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 of 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 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.

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 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.

Since:
JavaFX 8.0
  • Property Details

  • Constructor Details

    • TextFlow

      public TextFlow()
      Creates an empty TextFlow layout.
    • TextFlow

      public TextFlow(Node... children)
      Creates a TextFlow layout with the given children.
      Parameters:
      children - children.
  • Method Details

    • hitTest

      public final HitInfo hitTest(Point2D point)
      Maps local point to index in the content.
      Parameters:
      point - the specified point to be tested
      Returns:
      a HitInfo representing the character index found
      Since:
      9
    • caretShape

      public PathElement[] caretShape(int charIndex, boolean leading)
      Returns shape of caret in local coordinates.
      Parameters:
      charIndex - the character index for the caret
      leading - whether the caret is biased on the leading edge of the character
      Returns:
      an array of PathElement which can be used to create a Shape
      Since:
      9
    • rangeShape

      public final PathElement[] rangeShape(int start, int end)
      Returns shape for the range of the text in local coordinates.
      Parameters:
      start - the beginning character index for the range
      end - the end character index (non-inclusive) for the range
      Returns:
      an array of PathElement which can be used to create a Shape
      Since:
      9
    • setTextAlignment

      public final void setTextAlignment(TextAlignment value)
      Sets the value of the textAlignment property.
      Property description:
      Defines horizontal text alignment.
      Default value:
      TextAlignment.LEFT
      Parameters:
      value - the value for the textAlignment property
      See Also:
    • getTextAlignment

      public final TextAlignment getTextAlignment()
      Gets the value of the textAlignment property.
      Property description:
      Defines horizontal text alignment.
      Default value:
      TextAlignment.LEFT
      Returns:
      the value of the textAlignment property
      See Also:
    • textAlignmentProperty

      public final ObjectProperty<TextAlignment> 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 the lineSpacing property.
      Property description:
      Defines the vertical space in pixel between lines.
      Default value:
      0
      Parameters:
      spacing - the value for the lineSpacing property
      Since:
      JavaFX 8.0
      See Also:
    • getLineSpacing

      public final double getLineSpacing()
      Gets the value of the lineSpacing 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

      public final DoubleProperty lineSpacingProperty()
      Defines the vertical space in pixel between lines.
      Default value:
      0
      Returns:
      the lineSpacing property
      Since:
      JavaFX 8.0
      See Also:
    • tabSizeProperty

      public final IntegerProperty tabSizeProperty()
      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
      Returns:
      the tabSize property
      Since:
      14
      See Also:
    • getTabSize

      public final int getTabSize()
      Gets the value of the tabSize 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 contained Text nodes.
      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 the tabSize 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 contained Text nodes.
      Default value:
      8
      Parameters:
      spaces - the value for the tabSize property
      Since:
      14
      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, returns Node.getBaselineOffset().
      Overrides:
      getBaselineOffset in class Parent
      Returns:
      baseline offset
    • getClassCssMetaData

      public static List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
      Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.
      Returns:
      the CssMetaData