Search code examples
javacursorjtextarea

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


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?

Solution

  • Maybe this will help.

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