开发者

Java Swing - how to scroll down a JTextArea?

开发者 https://www.devze.com 2023-03-10 18:16 出处:网络
I have an application with 开发者_如何学Pythonbasic chat. I use JTextArea for the buffer. After adding a message I want to scroll to the bottom. How can this be achieved?

I have an application with 开发者_如何学Pythonbasic chat. I use JTextArea for the buffer. After adding a message I want to scroll to the bottom. How can this be achieved?

I found no member function that would allow me to do this.


You can do this by setting the caret position to the end of the text area, i.e.,

myTextArea.setCaretPosition(myTextArea.getDocument().getLength());

Edit: you can find out a lot more on this question by looking at the related questions listed on the lower right of this page. In particular, please check out camickr's answer and link in this thread: How to set AUTO-SCROLLING of JTextArea in Java GUI?. It's a far better and more complete answer than the one I've given (and I've just now up-voted it for this).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号