[Swing] JScrollPane double MouseMotionListener

O

oliv

hi,
I am targetting JRE 1.5.
I have an image displayed within a jscrollPane (with scrollbars).
(in this way : new JScrollPane(new JLabel(new ImageIcon(image))))

I have a MouseMotionListener added to the JScrollPane, so when the
mouse goes over the visible part of the image, I can get the relative
coordinates of the mouse


My question is how to I get at the same time, the coordinate of the
mouse relative to the jscrollpane (the coordinates within the visible
part of the image) and the absolute coordinates (the coordinates of
the mouse relative to the whole image itself).

I tried adding also MouseMotionListener to the JLabel and that gives
me the the coordinates of the mouse relative to the whole image
itself, but then the event is lost for the jscrollpane's listener.

How can I achieve that simply ?
 
O

oliv

hi,
I am targetting JRE 1.5.
I have an image displayed within a jscrollPane (with scrollbars).
(in this way : new JScrollPane(new JLabel(new ImageIcon(image))))

I have a MouseMotionListener added to the JScrollPane, so when the
mouse goes over the visible part of the image, I can get the relative
coordinates of the mouse

My question is how to I get at the same time, the coordinate of the
mouse relative to the jscrollpane (the coordinates within the visible
part of the image) and the absolute coordinates (the coordinates of
the mouse relative to the whole image itself).

I tried adding also MouseMotionListener to the JLabel and that gives
me the the coordinates of the mouse relative to the whole image
itself, but then the event is lost for the jscrollpane's listener.

How can I achieve that simply ?


Do not bother, I have found the solution :
only one listener added to the jscrollpane:
public void mouseMoved(MouseEvent e) {

System.out.println("mouseMoved() on jcrollpane relative "+e.getX()+"
"+e.getY());
System.out.println("mouseMoved() on jcrollpane absolute "+
(e.getX()+getHorizontalScrollBar().getValue())+" "+
(e.getY()+getVerticalScrollBar().getValue()));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top