Java Swing - 使用JScrollPane并将其滚动回顶部 [英] Java Swing - Using JScrollPane and Having it scroll back to top

查看:168
本文介绍了Java Swing - 使用JScrollPane并将其滚动回顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JScrollPane来允许在具有文本组件的JFrame中滚动,该文本组件用作文本编辑器。在我在此编辑器中设置文本后,我想要做的是将其向上滚动到顶部,这样你就可以看到文件开头的内容了。

I'm using JScrollPane to allow scrolling in a JFrame that has a text component that's serving as a text editor. What I want to do, after setting the text in this editor, is have it scroll back up to the top, so you can see what's at the beginning of the file.

有谁知道怎么做?

推荐答案

致电 setCaretPosition(0)将使其滚动到顶部。

Calling setCaretPosition(0) on your text component will cause it to scroll to the top.

这篇关于Java Swing - 使用JScrollPane并将其滚动回顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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