Top Description Methods
org.fxmisc.richtext

public Interface TextEditingArea<PS, SEG, S>

Known Direct Subinterfaces
org.fxmisc.richtext.EditActions, org.fxmisc.richtext.NavigationActions
Known Direct Implementers
org.fxmisc.richtext.GenericStyledArea
Type Parameters
<S>
type of style that can be applied to text.
Imports
javafx.beans.value.ObservableValue, javafx.collections.ObservableList, javafx.geometry.Bounds, javafx.scene.control.IndexRange, org.fxmisc.richtext.model.EditableStyledDocument, .Paragraph, .PlainTextChange, .RichTextChange, .SegmentOps, .StyledDocument, org.reactfx.EventStream, .SuspendableNo, org.reactfx.value.Var, java.util.List, .Locale, .Optional

Interface for a text editing control. Defines the core methods. Other interfaces define default higher-level methods implemented on top of the core methods.

Method Summary

Modifier and TypeMethod and Description
public default ObservableValue<Integer>
public SuspendableNo
beingUpdatedProperty()

True when an update to the area's underling editable document is still occurring or the viewport is being updated.

public default ObservableValue<Optional<Bounds>>
public default ObservableValue<Integer>
public default ObservableValue<Integer>
public MultiChangeBuilder<PS, SEG, S>
createMultiChange()

Starts building a list of changes to be used to update multiple portions of the underlying document in one call.

public MultiChangeBuilder<PS, SEG, S>
createMultiChange(int numOfChanges)

Same as createMultiChange() but the number of changes are specified to be more memory efficient.

public default ObservableValue<Integer>
public void
displaceCaret(int pos)

Displaces the caret from the selection by positioning only the caret to the new location without also affecting the selection's anchor or the selection.

public void
dispose()

Disposes this area, preventing memory leaks.

public int
getAbsolutePosition(int
The index of the paragraph from which to start.
paragraphIndex
,
int
If positive, the index going forward (the given paragraph's line or the next one(s)). If negative, the index going backward (the previous paragraph's line(s)
columnIndex
)

Returns the absolute position (i.e. the spot in-between characters) to the left of the given column in the given paragraph.

public default int
getAnchor()

The anchor of the selection.

public default Optional<Bounds>
getCaretBounds()

Gets the bounds of the caret in the Screen's coordinate system or Optional#empty() if caret is not visible in the viewport.

public default int
getCaretColumn()

The caret position within the current paragraph.

public default int
getCaretPosition()

The current position of the caret, as a character offset in the text.

public CaretSelectionBind<PS, SEG, S>
public EditableStyledDocument<PS, SEG, S>
getContent()

The underlying document of this area that can be displayed by multiple StyledTextAreas.

public default int
getCurrentParagraph()

Index of the current paragraph, i.e. the paragraph with the caret.

public StyledDocument<PS, SEG, S>
getDocument()

Rich-text content of this text-editing area.

public default int
getLength()

The number of Unicode code units in this text-editing area.

public default Locale
getLocale()

This is used to determine word and sentence breaks while navigating or selecting.

public default Paragraph<PS, SEG, S>
getParagraph(int index)

public default int
getParagraphLength(int index)

public ObservableList<Paragraph<PS, SEG, S>>
getParagraphs()

Unmodifiable observable list of paragraphs in this text area.

public default IndexRange
getParagraphSelection(int paragraph)

Returns the selection range in the given paragraph.

public IndexRange
getParagraphSelection(Selection<PS, SEG, S> selection, int paragraph)

public SegmentOps<SEG, S>
getSegOps()

Returns the object used for operating over segments and their styles

public default String
getSelectedText()

The selected text.

public default IndexRange
getSelection()

The selection range.

public default Optional<Bounds>
getSelectionBounds()

Gets the bounds of the selection in the Screen's coordinate system if something is selected and visible in the viewport or Optional#empty() if selection is not visible in the viewport.

public default Caret.CaretVisibility
getShowCaret()

Indicates when this text area should display a caret.

public default String
getText()

Text content of this text-editing area.

public String
getText(int paragraphIndex)

Returns text content of the given paragraph.

public String
getText(int start, int end)

Returns text content of the given character range.

public String
getText(IndexRange range)

Returns text content of the given character range.

public default String
getText(int startParagraph, int startColumn, int endParagraph, int endColumn)

Returns text content of the given character range.

public default boolean
public ObservableValue<Integer>
public EventStream<List<PlainTextChange>>
public EventStream<List<RichTextChange<PS, SEG, S>>>
public EventStream<PlainTextChange>
public void
replace(int start, int end, StyledDocument<PS, SEG, S> replacement)

Replaces a range of characters with the given rich-text document.

public void
replace(int
Start index of the range to replace, inclusive.
start
,
int
End index of the range to replace, exclusive.
end
,
SEG
The seg to put in place of the deleted range. It must not be null.
seg
,
S style)

Replaces a range of characters with the given segment.

public default void
replace(int startParagraph, int startColumn, int endParagraph, int endColumn, SEG
The segment to put in place of the deleted range. It must not be null.
seg
,
S style)

Replaces a range of characters with the given segment.

public default void
replace(int startParagraph, int startColumn, int endParagraph, int endColumn, StyledDocument<PS, SEG, S> replacement)

Replaces a range of characters with the given rich-text document.

public default void
replace(IndexRange
The range to replace. It must not be null.
range
,
SEG
The segment to put in place of the deleted range. It must not be null.
seg
,
S style)

Replaces a range of characters with the given seg.

public default void
replace(IndexRange range, StyledDocument<PS, SEG, S> replacement)

Equivalent to replace(range.getStart(), range.getEnd(), replacement).

public void
replaceText(int
Start index of the range to replace, inclusive.
start
,
int
End index of the range to replace, exclusive.
end
,
String
The text to put in place of the deleted range. It must not be null.
text
)

Replaces a range of characters with the given text.

public default void
replaceText(int startParagraph, int startColumn, int endParagraph, int endColumn, String
The text to put in place of the deleted range. It must not be null.
text
)

Replaces a range of characters with the given text.

public default void
replaceText(IndexRange
The range to replace. It must not be null.
range
,
String
The text to put in place of the deleted range. It must not be null.
text
)

Replaces a range of characters with the given text.

public EventStream<RichTextChange<PS, SEG, S>>
public default ObservableValue<String>
public default ObservableValue<Optional<Bounds>>
public default ObservableValue<IndexRange>
public default void
selectRange(int anchor, int caretPosition)

Positions the anchor and caretPosition explicitly, effectively creating a selection.

public default void
selectRange(int anchorParagraph, int anchorColumn, int caretPositionParagraph, int caretPositionColumn)

Positions the anchor and caretPosition explicitly, effectively creating a selection.

public default void
public default Var<Caret.CaretVisibility>
public StyledDocument<PS, SEG, S>
subDocument(int paragraphIndex)

Returns rich-text content of the given paragraph.

public default StyledDocument<PS, SEG, S>
subDocument(IndexRange range)

Returns rich-text content of the given character range.

public StyledDocument<PS, SEG, S>
subDocument(int start, int end)

Returns rich-text content of the given character range.

public default StyledDocument<PS, SEG, S>
subDocument(int startParagraph, int startColumn, int endParagraph, int endColumn)

Returns rich-text content of the given character range.

public ObservableValue<String>

Method Detail

anchorPropertyback to summary
public default ObservableValue<Integer> anchorProperty()
beingUpdatedPropertyback to summary
public SuspendableNo beingUpdatedProperty()

True when an update to the area's underling editable document is still occurring or the viewport is being updated.

caretBoundsPropertyback to summary
public default ObservableValue<Optional<Bounds>> caretBoundsProperty()
caretColumnPropertyback to summary
public default ObservableValue<Integer> caretColumnProperty()
caretPositionPropertyback to summary
public default ObservableValue<Integer> caretPositionProperty()
createMultiChangeback to summary
public MultiChangeBuilder<PS, SEG, S> createMultiChange()

Starts building a list of changes to be used to update multiple portions of the underlying document in one call. To execute the changes, call MultiChangeBuilder#commit(). If the number of changes are known at compile time, use createMultiChange(int) for better memory efficiency.

createMultiChangeback to summary
public MultiChangeBuilder<PS, SEG, S> createMultiChange(int numOfChanges)

Same as createMultiChange() but the number of changes are specified to be more memory efficient.

currentParagraphPropertyback to summary
public default ObservableValue<Integer> currentParagraphProperty()
displaceCaretback to summary
public void displaceCaret(int pos)

Displaces the caret from the selection by positioning only the caret to the new location without also affecting the selection's anchor or the selection. Do not confuse this method with NavigationActions#moveTo(int), which is the normal way of moving the caret. This method can be used to achieve the special case of positioning the caret outside or inside the selection, as opposed to always being at the boundary. Use with care.

disposeback to summary
public void dispose()

Disposes this area, preventing memory leaks.

getAbsolutePositionback to summary
public int getAbsolutePosition(int paragraphIndex, int columnIndex)

Returns the absolute position (i.e. the spot in-between characters) to the left of the given column in the given paragraph.

For example, given a text with only one line "text" and the columnIndex value of 1, "position 1" would be returned:

 ┌ character index 0
 | ┌ character index 1
 | |   ┌ character index 3
 | |   |
 v v   v

|t|e|x|t|

^ ^     ^
| |     |
| |     └ position 4
| └ position 1
└ position 0

Warning: Off-By-One errors can easily occur

If the column index spans outside of the given paragraph's length, the returned value will pass on to the previous/next paragraph. In other words, given a document with two paragraphs (where the first paragraph's text is "some" and the second "thing"), then the following statements are true:

  • getAbsolutePosition(0, "some".length()) == 4 == getAbsolutePosition(1, -1)
  • getAbsolutePosition(0, "some".length() + 1) == 5 == getAbsolutePosition(1, 0)
Parameters
paragraphIndex:int

The index of the paragraph from which to start.

columnIndex:int

If positive, the index going forward (the given paragraph's line or the next one(s)). If negative, the index going backward (the previous paragraph's line(s)

getAnchorback to summary
public default int getAnchor()

The anchor of the selection. If there is no selection, this is the same as caret position.

getCaretBoundsback to summary
public default Optional<Bounds> getCaretBounds()

Gets the bounds of the caret in the Screen's coordinate system or Optional#empty() if caret is not visible in the viewport.

getCaretColumnback to summary
public default int getCaretColumn()

The caret position within the current paragraph.

getCaretPositionback to summary
public default int getCaretPosition()

The current position of the caret, as a character offset in the text. Most of the time, caret is at the boundary of the selection (if there is any selection). However, there are circumstances when the caret is positioned inside or outside the selected text. For example, when the user is dragging the selected text, the caret moves with the cursor to point at the position where the selected text moves upon release.

getCaretSelectionBindback to summary
public CaretSelectionBind<PS, SEG, S> getCaretSelectionBind()

Gets the area's main CaretSelectionBind.

getContentback to summary
public EditableStyledDocument<PS, SEG, S> getContent()

The underlying document of this area that can be displayed by multiple StyledTextAreas.

getCurrentParagraphback to summary
public default int getCurrentParagraph()

Index of the current paragraph, i.e. the paragraph with the caret.

getDocumentback to summary
public StyledDocument<PS, SEG, S> getDocument()

Rich-text content of this text-editing area. The returned document is immutable, it does not reflect subsequent edits of this text-editing area.

getLengthback to summary
public default int getLength()

The number of Unicode code units in this text-editing area.

getLocaleback to summary
public default Locale getLocale()

This is used to determine word and sentence breaks while navigating or selecting. Override this method if your paragraph or text style accommodates Locales as well.

getParagraphback to summary
public default Paragraph<PS, SEG, S> getParagraph(int index)
getParagraphLengthback to summary
public default int getParagraphLength(int index)
getParagraphsback to summary
public ObservableList<Paragraph<PS, SEG, S>> getParagraphs()

Unmodifiable observable list of paragraphs in this text area.

getParagraphSelectionback to summary
public default IndexRange getParagraphSelection(int paragraph)

Returns the selection range in the given paragraph.

Note

this method will return IndexRange(start, paragraph.length() + 1) when the selection includes a newline character.

getParagraphSelectionback to summary
public IndexRange getParagraphSelection(Selection<PS, SEG, S> selection, int paragraph)
getSegOpsback to summary
public SegmentOps<SEG, S> getSegOps()

Returns the object used for operating over segments and their styles

getSelectedTextback to summary
public default String getSelectedText()

The selected text.

getSelectionback to summary
public default IndexRange getSelection()

The selection range. One boundary is always equal to anchor, and the other one is most of the time equal to caret position.

getSelectionBoundsback to summary
public default Optional<Bounds> getSelectionBounds()

Gets the bounds of the selection in the Screen's coordinate system if something is selected and visible in the viewport or Optional#empty() if selection is not visible in the viewport.

getShowCaretback to summary
public default Caret.CaretVisibility getShowCaret()

Indicates when this text area should display a caret.

getTextback to summary
public default String getText()

Text content of this text-editing area.

getTextback to summary
public String getText(int paragraphIndex)

Returns text content of the given paragraph.

getTextback to summary
public String getText(int start, int end)

Returns text content of the given character range.

getTextback to summary
public String getText(IndexRange range)

Returns text content of the given character range.

getTextback to summary
public default String getText(int startParagraph, int startColumn, int endParagraph, int endColumn)

Returns text content of the given character range.

Caution

see getAbsolutePosition(int, int) to know how the column index argument can affect the returned position.

isBeingUpdatedback to summary
public default boolean isBeingUpdated()
lengthPropertyback to summary
public ObservableValue<Integer> lengthProperty()
multiPlainChangesback to summary
public EventStream<List<PlainTextChange>> multiPlainChanges()

See org.fxmisc.richtext.model.EditableStyledDocument#multiPlainChanges()

multiRichChangesback to summary
public EventStream<List<RichTextChange<PS, SEG, S>>> multiRichChanges()

See org.fxmisc.richtext.model.EditableStyledDocument#multiRichChanges()

plainTextChangesback to summary
public EventStream<PlainTextChange> plainTextChanges()

See org.fxmisc.richtext.model.EditableStyledDocument#plainChanges()

replaceback to summary
public void replace(int start, int end, StyledDocument<PS, SEG, S> replacement)

Replaces a range of characters with the given rich-text document.

replaceback to summary
public void replace(int start, int end, SEG seg, S style)

Replaces a range of characters with the given segment. It must hold 0 <= start <= end <= getLength().

Parameters
start:int

Start index of the range to replace, inclusive.

end:int

End index of the range to replace, exclusive.

seg:SEG

The seg to put in place of the deleted range. It must not be null.

replaceback to summary
public default void replace(int startParagraph, int startColumn, int endParagraph, int endColumn, SEG seg, S style)

Replaces a range of characters with the given segment. It must hold 0 <= start <= end <= getLength() where start = getAbsolutePosition(startParagraph, startColumn); and is inclusive, and int end = getAbsolutePosition(endParagraph, endColumn); and is exclusive.

Caution

see getAbsolutePosition(int, int) to know how the column index argument can affect the returned position.

Parameters
seg:SEG

The segment to put in place of the deleted range. It must not be null.

replaceback to summary
public default void replace(int startParagraph, int startColumn, int endParagraph, int endColumn, StyledDocument<PS, SEG, S> replacement)

Replaces a range of characters with the given rich-text document.

Caution

see getAbsolutePosition(int, int) to know how the column index argument can affect the returned position.

replaceback to summary
public default void replace(IndexRange range, SEG seg, S style)

Replaces a range of characters with the given seg.

Parameters
range:IndexRange

The range to replace. It must not be null.

seg:SEG

The segment to put in place of the deleted range. It must not be null.

See Also
replace(int, int, Object, Object)
replaceback to summary
public default void replace(IndexRange range, StyledDocument<PS, SEG, S> replacement)

Equivalent to replace(range.getStart(), range.getEnd(), replacement).

replaceTextback to summary
public void replaceText(int start, int end, String text)

Replaces a range of characters with the given text. It must hold 0 <= start <= end <= getLength().

Parameters
start:int

Start index of the range to replace, inclusive.

end:int

End index of the range to replace, exclusive.

text:String

The text to put in place of the deleted range. It must not be null.

replaceTextback to summary
public default void replaceText(int startParagraph, int startColumn, int endParagraph, int endColumn, String text)

Replaces a range of characters with the given text. It must hold 0 <= start <= end <= getLength() where start = getAbsolutePosition(startParagraph, startColumn); and is inclusive, and int end = getAbsolutePosition(endParagraph, endColumn); and is exclusive.

Caution

see getAbsolutePosition(int, int) to know how the column index argument can affect the returned position.

Parameters
text:String

The text to put in place of the deleted range. It must not be null.

replaceTextback to summary
public default void replaceText(IndexRange range, String text)

Replaces a range of characters with the given text.

Parameters
range:IndexRange

The range to replace. It must not be null.

text:String

The text to put in place of the deleted range. It must not be null.

See Also
replaceText(int, int, String)
richChangesback to summary
public EventStream<RichTextChange<PS, SEG, S>> richChanges()

See org.fxmisc.richtext.model.EditableStyledDocument#richChanges()

selectedTextPropertyback to summary
public default ObservableValue<String> selectedTextProperty()
selectionBoundsPropertyback to summary
public default ObservableValue<Optional<Bounds>> selectionBoundsProperty()
selectionPropertyback to summary
public default ObservableValue<IndexRange> selectionProperty()
selectRangeback to summary
public default void selectRange(int anchor, int caretPosition)

Positions the anchor and caretPosition explicitly, effectively creating a selection.

selectRangeback to summary
public default void selectRange(int anchorParagraph, int anchorColumn, int caretPositionParagraph, int caretPositionColumn)

Positions the anchor and caretPosition explicitly, effectively creating a selection.

Caution

see getAbsolutePosition(int, int) to know how the column index argument can affect the returned position.

setShowCaretback to summary
public default void setShowCaret(Caret.CaretVisibility value)
showCaretPropertyback to summary
public default Var<Caret.CaretVisibility> showCaretProperty()
subDocumentback to summary
public StyledDocument<PS, SEG, S> subDocument(int paragraphIndex)

Returns rich-text content of the given paragraph.

subDocumentback to summary
public default StyledDocument<PS, SEG, S> subDocument(IndexRange range)

Returns rich-text content of the given character range.

subDocumentback to summary
public StyledDocument<PS, SEG, S> subDocument(int start, int end)

Returns rich-text content of the given character range.

subDocumentback to summary
public default StyledDocument<PS, SEG, S> subDocument(int startParagraph, int startColumn, int endParagraph, int endColumn)

Returns rich-text content of the given character range.

Caution

see getAbsolutePosition(int, int) to know how the column index argument can affect the returned position.

textPropertyback to summary
public ObservableValue<String> textProperty()