Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

[Swing] JScrollPane double MouseMotionListener

Thread view: 
oliv@linuxmail.org - 11 Mar 2007 17:40 GMT
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 ?
oliv@linuxmail.org - 11 Mar 2007 17:47 GMT
On 11 mar, 17:40, o...@linuxmail.org wrote:
> hi,
> I am targetting JRE 1.5.
[quoted text clipped - 15 lines]
>
> 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()));


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.