Reputation: 63
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?
Upvotes: 2
Views: 1846
Reputation: 324108
Not sure but I think you need to use:
component.setAutoscrolls( false );
Upvotes: 3
Reputation: 11999
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 MouseListener
s and/or MouseMotionListener
s 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.
Upvotes: 2