JScrollPane:禁用拖动滚动

发布于 2024-12-13 15:23:16 字数 728 浏览 2 评论 0原文

我正在使用一些 JGraphX 组件,但这个问题可以应用于 java 的一般用途。

我在 JScrollPane 中有一个组件。我遇到的问题是,我能够通过“抓取”视图并像谷歌地图一样移动它来平移视图。但如果光标离开视口,滚动方向就会改变。我做了一些研究并发现了导致问题的问题。可以在本页的下半部分找到它,其中开始讨论滚动窗格的工作原理。

http://download.oracle.com/javase/tutorial/uiswing/components /scrollpane.html

将光标移到图像上并按光标。继续 按下光标,拖动到图像外的一点并暂停。这 图像的可见区域向光标移动。这 滚动窗格启用拖动滚动功能,并且 与JComponent API,但它是由自定义组件实现的 显示图像。

它有一个小演示,因此您可以看到它是如何工作的,并且代码可供下载。

因此,默认情况下,滚动窗格具有滚动拖动功能,但实际上与我需要的滚动方式相反。我正在使用的 JGraphX 库扩展了大多数用于以某种方式使自身受益的类,但基本思想仍然适用。我真的只需要知道禁用此功能的最简单方法。 Yhe 页面说它是由滚动窗格和 JComponent API 启用的,但实际上启用了什么?

I am using some JGraphX components but this question can be applied to a general purpose of java.

I have a component inside of a JScrollPane. The issue I am having is that I have the ability to pan in the view by "grabbing" the view and moving it around like Google maps. but if the cursor leaves the viewport the scrolling changes directions. I have done some research and found the issue causing the problem. It can be found part of the way down on this page where it starts talking about how the scrollpane works.

http://download.oracle.com/javase/tutorial/uiswing/components/scrollpane.html

Move the cursor over the image and press the cursor. Continuing to
press the cursor, drag to a point outside the image and pause. The
visible area of the image moves toward the cursor. This
scroll-by-dragging functionality is enabled by the scroll pane, and
with the JComponent API, but it is implemented by the custom component
that displays the image.

It has the little demo so you can see how it works as well as the code is available for download.

So by default the scrollpane has a scroll to drag implemented but it is actually opposite of how I need mine to scroll. The JGraphX library I am using has extended most of the classes used to benefit itself in some way but the basic idea still applies. I really just need to know of the easiest way to disable this. Yhe page says its enabled by the scrollpane and the JComponent API, but what actually gets enabled?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

谜泪 2024-12-20 15:23:16

不确定,但我认为你需要使用:

component.setAutoscrolls( false );

Not sure but I think you need to use:

component.setAutoscrolls( false );
风启觞 2024-12-20 15:23:16

此方法来自JComponent 看起来是最好的研究起点。您可以检索滚动窗格中的组件并使用 false 调用该方法。这是默认设置,但 JGraphX 可能默认启用它。

或者,您可以从滚动窗格中获取 MouseListener 和/或 MouseMotionListener 并将它们替换为覆盖拖动行为的内容。由于这些是接口,您可以使用 代理 对象。不过,看起来有点老套。

This method from JComponent looks like the best starting point to investigate. You could retrieve the component in your scroll pane and call that method with false on it. That's the default, but it's possible JGraphX has it enabled by default.

Alternatively, you could get the MouseListeners and/or MouseMotionListeners from the scroll pane and replace them with something that overrides the dragging behaviour. Since those are interfaces, you could use proxy objects for that. Seems somewhat hacky, though.

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