Automatically scroll to the bottom of a text area

后端 未结 2 426
太阳男子
太阳男子 2020-12-29 09:14

I have a text area with scroll bar. At regular intervals, I am adding new lines of text to it. I would like the text area to automatically scroll to the bottom-most entry (t

相关标签:
2条回答
  • 2020-12-29 09:50
    textArea.setCaretPosition(textArea.getDocument().getLength());
    
    0 讨论(0)
  • 2020-12-29 09:51

    Have a look at the updatePolicy property of DefaultCaret: it might do what you want

    DefaultCaret caret = (DefaultCaret) textArea.getCaret();
    caret.setUpdatePolicy(ALWAYS_UPDATE);
    

    A nice summary of options by Rob (@camickr)

    0 讨论(0)
提交回复
热议问题