How to change the default position of a cursor in a JTextArea?

a 夏天 提交于 2019-12-11 13:37:55

问题


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?

回答1:


Maybe this will help.

_result.setCaretPosition(_result.getText().length());  



回答2:


You could also try:

_result.setText(""), 

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




回答3:


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.



来源:https://stackoverflow.com/questions/17768212/how-to-change-the-default-position-of-a-cursor-in-a-jtextarea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!