填充文本区域后将其滚动到顶部

发布于 2025-01-01 04:45:42 字数 66 浏览 1 评论 0原文

我有一些文本区域,里面充满了信息循环。是否可以在循环完成后使其“跳转”或自动滚动回顶部,以便用户从头看到它而不是结束?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

春花秋月 2025-01-08 04:45:42

您可以使用setCaretPosition()将光标设置在TextArea的位置0处。这通常对我有用。

You can use setCaretPosition() to set the cursor at position 0 of the TextArea. That usually works for me.

智商已欠费 2025-01-08 04:45:42

将 setUpdatePolicy 与 NEVER_UPDATE 一起使用,并确保 setUpdatePolicy 在将任何文本设置到 JTextArea 之前出现。在我的示例中,我初始化了一个没有任何文本的 JTextArea,并在之后立即调用 setUpdatePolicy。

JTextArea jTextArea = new JTextArea();
((DefaultCaret)jTextArea.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);

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.

JTextArea jTextArea = new JTextArea();
((DefaultCaret)jTextArea.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
坦然微笑 2025-01-08 04:45:42

我通过创建一个新的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文