停用 JScrollPane 上的 ScrollOnExpand
我想防止滚动窗格在视图中的内容展开时滚动。有什么指点吗?我尝试过用谷歌搜索标题的变体,并阅读了 JScrollPane 的所有文档,但我仍然有点困惑。
编辑: 在滚动窗格中,我有一个文本窗格,在它旁边有另一个文本窗格,显示旁边窗格的行号。每次添加新行时我都会填充此数字窗格,因此这可能是导致视图前进的原因。
I want to prevent the scrollpane from scrolling when the content in its view expands. Any pointers? I've tried Googling variations on the title, as well as reading all the docs for JScrollPane, and I'm still a bit baffled.
Edit:
Within the scroll pane, I have a textpane, and beside it I have another text pane that shows the line numbers of the pane beside it. I fill up this number pane every time a new line is added, so this is probably what is causing the view to advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以在 DefaultCaret 上配置滚动或不滚动
另请参阅 Rob 的精彩博客条目 关于文本滚动
to-scroll or not-to-scroll is configurable on DefaultCaret
See also Rob's nice blog entry about text scrolling
通常 JScrollPane 不会这样做,当
您使用类似“也许您的组件发生变化,以至于您将其视为“滚动””的 代码放大视口时,
getViewport().getViewPosition()
保持固定。在这种情况下,您必须在放大视图后使用scrollPane.getViewport().setViewPosition(...)
调整视图位置。Usually JScrollPane does not do that, the
getViewport().getViewPosition()
remains fixed when you enlarge the view port with code likeMaybe your component changes in such a way that you perceive it as "scrolling". In that case you have to adjust the view position with
scrollPane.getViewport().setViewPosition(...)
after enlarging the view..