I extended MouseAdapter and added it as MouseListener to JDialog.
The most interesting is that when I enter or exit JDialog by moving mouse I have both mouseEntered and mouseExited run together one after another.
This is proved by println statements. They truly run one after the other when I enter or exit jDialog.
My code is simple and there is nothing especial.
All Swing components have a parent/child relationship. So a dialog contains a root pane which contains a layered pane, which contains a content pane, which contains other panels and component of your application. So as you move you mouse from one component to the next you generate mouse entered/exited events.
When you add your listener to the dialog I'm not sure which component the listener actually gets added to. Check out Global Event Listeners. Use the AWTEVentListener and also print out the source of the event so you can see which component the event is being generated for.
To add MouseListener I call addMouseListener of JDialog like so :
As you see I check if mouse exited my dialog ConnectionTreeTooltip. But this method still works when I really enter the dialog.
AwtListenet seems to be for all components in my aplication. Can I add AWTListener to single component like JDialog.
I print my event and the output is always the same :
The funny thing is that this MOUSE_EXITED event is generated when I try to enter my dialog for the first time.
Also MOUSE_EXITED event is not generating always when mouse is exiting dialog. This is bad because when dialog is exited by mouse it must be hidden.
As a result I have my dialog disappear when I try to enter it and when I exit, it does not disappear.
I still do not understand what JRootPane has to do with my problem. I see that mouse event is always for the same dialog0.