如何防止 JScrollPane 在重绘时向下滚动?
我有一个 JScrollPane,里面有一个图表。图表的paintComponent方法被覆盖。现在,当图表自行绘制时,滚动窗格会向下滚动到底部。
如何防止滚动? 我希望滚动窗格/滚动条在绘画时保持其位置。
提前致谢。
I have got a JScrollPane with a diagram inside. The paintComponent Methode of the diagram is overridden. Now when the diagram paints itself, the scrollpane scrolls down to the buttom.
How do I prevent the scrolling?
I want the scrollpane / scrollbar to hold its position when painting.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从未见过这种情况发生。这可能是因为您添加到 PaintComponent() 方法中的一些代码。
您可以尝试使用 repaint(Rectangle) 来限制已完成的重绘。
如果您需要更多帮助,请发布说明问题的 SSCCE。
I've never seen this happen. Its probably because of some code you added to your paintComponent() method.
You could try using repaint(Rectangle) to limit the repainting that is done.
If you need more help post your SSCCE that demonstrates the problem.
当调用paintComponent 时,典型的Swing 组件中没有任何行为会导致其滚动。我会在您的自定义绘画代码中查找对名为
scrollRectToVisible
的方法的调用。这是使组件在其窗格内滚动的常见方法。There's no behavior in a typical Swing component that would cause it to scroll when paintComponent is called. I would look in your custom painting code for calls to a method called
scrollRectToVisible
. This is a common way of causing a component to be scrolled within it's pane.