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 / February 2006

Tip: Looking for answers? Try searching our database.

Fire mouseExited only when leaving panel boundaries?

Thread view: 
PilotYid - 07 Feb 2006 23:05 GMT
I am having some trouble with the mouseExited event in
MouseAdapter/MouseListener. I have a Panel with 3 labels on it. I would
like to start a timer when the mouse is anywhere over this panel
(including the labels), and stop the timer when it leaves the panel
boundaries. I have added a mouselistener to do this but when moving
internally within the panel from the panel to a label, I am getting a
mouseexited on the Panel which is stopping the timer. Is there anyway
to get around this? I only want to do something upon leaving the Panel
boundaries, not when moving internally within the panel to a label,
etc.
The labels inside the Panel do not have to handle any events.
I have to use Java 1.1 as well. Would some kind of glasspane work here?

Thanks for your help,
Aaron
Douwe - 07 Feb 2006 23:40 GMT
PilotYid schrieb:

> I am having some trouble with the mouseExited event in
> MouseAdapter/MouseListener. I have a Panel with 3 labels on it. I would
[quoted text clipped - 11 lines]
> Thanks for your help,
> Aaron

You could use the next piece of code to check if the last position is
still inside the boundaries of the panel.

  class MyMouseAdapter extends MouseAdapter {
     public void mouseExited(MouseEvent e) {
        boolean insidePanel = ((JPanel)
e.getSource()).getBounds().inside(e.getX(), e.getY());
        if (!insidePanel) {
           return;
        }
        System.out.println("do your stuff here");
     }
   }

You can only use a glasspane on a JFrame if  that is not a problem you
could use that to. If you need to get mouse-motion-events the glasspane
is probably the only valid method.
PilotYid - 07 Feb 2006 23:55 GMT
Thanks, Ill take a look at that. But wouldnt the X and Y always be
inside the Panel,
even if the mouse is leaving the panel boundaries? Or is the X/Y the
coords of the pointer as soon as it leaves? That is, if the mouse is
leaving the panel, what would the X/Y be on mouseExited? the last point
inside the
panel, or the first point outside it?

Thanks
Douwe - 10 Feb 2006 21:34 GMT
Apparently the X and Y are the position outside the rectangle. I wrote
a small test program myself so it shouls work :)


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



©2009 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.