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