自动滚动到文本区域的底部 [英] Automatically scroll to the bottom of a text area

查看:150
本文介绍了自动滚动到文本区域的底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带滚动条的文本区域。我定期添加新的文本行。每当添加新行时,我希望文本区域自动滚动到最底部的条目(最新的条目)。我怎样才能做到这一点?

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 (the newest one) whenever a new line is added. How can I accomplish this?

textAreaStatus = new WebTextArea();
scrollPane = new JScrollPane(textAreaStatus);
textAreaStatus.setBackground(Color.black);
textAreaStatus.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));


推荐答案

查看DefaultCaret的updatePolicy属性:it可能做你想做的事情

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 选项的精彩摘要(@camickr)

A nice summary of options by Rob (@camickr)

这篇关于自动滚动到文本区域的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆