3

I want to set the caret position to the end of a Text after appending text to a StyledText.

How do I achieve this? Set caret at the end of the text

This is in continuation to my earlier question

Community
  • 1
  • 1
srk
  • 4,857
  • 12
  • 65
  • 109

2 Answers2

6

I have never used StyledText but looking at the API shows a method called setCaretOffset( int offset ) which takes a number that is the offset from the beginning of the text. So you could call getText(), find its length, and then set the caret to be that number as the offset.

*I like the answer that Travis posted below. I didn't notice the method getCharacterCount() on StyledSheet. That is probably a little cheaper then getting the text then the length.

Matt N
  • 146
  • 5
2

I found a solution to my question.

I tried this, but this was not preferable to me.

styledText.selectAll();//moves the scroll bar down but selects all text.

This worked for me!

styledText.setSelection(styledText.getCharacterCount());

My gratitude to all for the above answers.

Animesh
  • 4,926
  • 14
  • 68
  • 110
srk
  • 4,857
  • 12
  • 65
  • 109