填充文本区域后将其滚动到顶部
我有一些文本区域,里面充满了信息循环。是否可以在循环完成后使其“跳转”或自动滚动回顶部,以便用户从头看到它而不是结束?
I have a few text areas that are filled with loops of information. Is it possible to make it 'jump' or scroll back to the top automatically after the loop has completed, so that the user sees it from the start and not the end?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
setCaretPosition()
将光标设置在TextArea的位置0处。这通常对我有用。You can use
setCaretPosition()
to set the cursor at position 0 of the TextArea. That usually works for me.将 setUpdatePolicy 与 NEVER_UPDATE 一起使用,并确保 setUpdatePolicy 在将任何文本设置到 JTextArea 之前出现。在我的示例中,我初始化了一个没有任何文本的 JTextArea,并在之后立即调用 setUpdatePolicy。
Use setUpdatePolicy with NEVER_UPDATE, and make sure the setUpdatePolicy comes before setting any text to the JTextArea. In my example I initialize a JTextArea without any text and call setUpdatePolicy right after.
我通过创建一个新的 TextArea 解决了这个问题,它充当一种缓冲区(并且不显示)。循环写入该区域,完成后从中获取文本并将其设置到所需的 TextArea。
I have solved this problem by creating a new TextArea which acts as a sort of buffer (and isn't displayed). The loop writes to this area and when completed gets the text from that and sets it to the required TextArea.