How to change the default position of a cursor in

2019-08-04 01:53发布

I have a _result JtextArea. Every second there is a new piece of text String being appended to it. By default, the cursor is at the top. I need the cursor always to be at the very end of the text in the JTextArea. So that I could see what is the last String being appended.

  _result.append("my text");
    // How do I make the cursor of `_result` JTextArea to be at the end of the text?

3条回答
倾城 Initia
2楼-- · 2019-08-04 02:12

There is no append() method for a JTextField. I assume you are talking about a JTextArea.

By default, the cursor is at the top.

By default the caret should display at the end of the text. If not then you may be doing something wrong. Ccheck out Text Area Scrolling for more information and a couple of solutions.

查看更多
一纸荒年 Trace。
3楼-- · 2019-08-04 02:15

Maybe this will help.

_result.setCaretPosition(_result.getText().length());  
查看更多
来,给爷笑一个
4楼-- · 2019-08-04 02:18

You could also try:

_result.setText(""), 

then try to append the new text if you only wish to see only the appended text.

查看更多
登录 后发表回答