Java / Swing : JTextArea in a JScrollPane, how to prevent auto-scroll?

前端 未结 3 1751
南旧
南旧 2020-11-30 10:42

here\'s a runnable piece of code that shows what my \"problem\" is.

I\'ve got a JTextArea wrapped in a JScrollPane. When I change the text

3条回答
  •  失恋的感觉
    2020-11-30 11:08

    Answering my own question: I'm not exactly sure this is the best way to solve my issue, but setting the JTextArea's caret using setCaretPosition(0) seems to work fine:

    jta.setText( sb.toString() );
    jta.jta.setCaretPosition( 0 );
    

提交回复
热议问题