调整 JScrollPane 客户端的大小而不滚动滚动条
我有一个 JScrollpane,其中包含一个可滚动客户端,可以在使用应用程序时动态更改其大小。我希望 JScrollPane 能够在客户端大小更改时了解更改,而无需移动视口。
为了澄清我的意思: 请参阅 Java Webstart 示例 ScrollDemo2摘自 Sun 的文章如何使用滚动窗格。单击窗口底部时,窗口的一部分会出现一个圆圈,并且滚动条会移动。这是我想避免的后一种行为。
我的猜测是,这只是在滚动窗格解决方案涉及的众多组件之一中设置一个简单标志的问题,但我只是找不到它在哪里。有谁知道吗?
I have a JScrollpane which contains a scrollable client that changes its size dynamically while using the application. I want the JScrollPane to be aware of the changes without moving the viewport when the client size changes.
To clarify what I mean:
Refer to the Java Webstart example ScrollDemo2 from the article How to use scroll panes by Sun. When clicking at the bottom of the window, a circle appears partly outside the window and the scrollbars move. It's the latter behavior I want to avoid.
My guess is that it's just a matter of setting a simple flag in one of the many components that are involved in a scroll pane solution, but I just can't find where it is. Does anyone know?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我设法通过覆盖 JScrollPane 中视口的标准行为来解决这个问题。这可能是一个并不适合所有人的解决方案,但在我的 GUI 中,这就像一个魅力。
I managed to solve this problem by overriding the standard behavior of the viewport in my JScrollPane. This might be a solution that is not suitable for all, but in my GUI this works like a charm.
我会尝试类似的操作:
您可能需要将最后一行代码包装在 SwingUtilities.invokeLater 中。
如果这不起作用,那么也许您可以在 revalidate() 之前和之后禁用/启用视口?
I would try something like:
You may need to wrap the last line of code in a SwingUtilities.invokeLater.
If that doesn't work then maybe you can disable/enable the viewport before and after the revalidate()?