Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why mouseEntered together with mouseExited run when mouse enters or exit JDialog?  RSS feed

 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

This is very funny and it is big issue.

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.

Can it be and why can it be?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps the API for JRootPane would help you understand why that happens.
 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply!

I got confused more rather than understood. I didn't find anything related to my issue
except that GlassPane can intercept mouse events and redispatch them to specific component in layered pane.

Can you be more specific?
 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!