Fire mouseExited only when leaving panel boundaries?

P

PilotYid

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
 
D

Douwe

PilotYid said:
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.
 
P

PilotYid

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
 
D

Douwe

Apparently the X and Y are the position outside the rectangle. I wrote
a small test program myself so it shouls work :)
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top