[英]How to set the caret position at the end of the text?
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. 我从未使用过StyledText,但查看API会显示一个名为
setCaretOffset( int offset )
的方法,该方法采用的数字是文本开头的偏移量。 So you could call getText()
, find its length, and then set the caret to be that number as the offset. 因此,您可以调用
getText()
,查找其长度,然后将插入符号设置为该数字作为偏移量。
*I like the answer that Travis posted below. *我喜欢Travis在下面发布的答案。 I didn't notice the method getCharacterCount() on StyledSheet.
我没有注意到StyledSheet上的方法getCharacterCount()。 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. 感谢所有人对上述答案的感谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.