mabafu
mabafu

Reputation: 11

JavaFX 8 TextArea: Select a substring and scroll to it

I wish to search a TextArea for some substring and, if its found, to select and scroll to it's position.

The search is not the issue, neither is the selection. What's troubling me is the TextArea scrolling.

I've tried so far:

TextArea.caretPosition(int)/ TextArea.selectPositionCaret(int);

TextArea.caretPosition(int) / TextArea.extendSelection(int);

TextArea.selectRange(int, int)

But none of them seems to scrolls the TextArea to the so selected text.

Any hints?

Upvotes: 0

Views: 385

Answers (1)

mabafu
mabafu

Reputation: 11

I've just found my mistake...

The TextArea control must have the focus prior the selection changes.

All it's need:

TextArea.requestFocus();
TextArea.selectRange(int, int);

Upvotes: 1

Related Questions