Re: Fire mouseExited only when leaving panel boundaries?
- From: "Douwe" <dmvos2000@xxxxxxxxx>
- Date: 7 Feb 2006 15:40:25 -0800
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
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
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.
.
- Follow-Ups:
- Re: Fire mouseExited only when leaving panel boundaries?
- From: PilotYid
- Re: Fire mouseExited only when leaving panel boundaries?
- References:
- Fire mouseExited only when leaving panel boundaries?
- From: PilotYid
- Fire mouseExited only when leaving panel boundaries?
- Prev by Date: Re: while(true) { try{ ... } catch(Exception e) { ... } }
- Next by Date: Re: Multithreading / Scalability
- Previous by thread: Fire mouseExited only when leaving panel boundaries?
- Next by thread: Re: Fire mouseExited only when leaving panel boundaries?
- Index(es):
Relevant Pages
|