How to make popup invisible
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
If I run the following application and then right-click on the
application, a popup menu will show up. If I move mouse outside the frame (I try to make JComponent visible so that I can move mouse outside JComponent, but I cannot make it happen), popup menu is still visible. I try to add the following to mouseExited method:
popupMenu.setVisible(false);
or add the following to let popup listen to mouse listener:
But these seemingly will disable pupup menu.
What I try to do is: make popup disappear once user move her mouse outside frame (better yet JComponent). How can I do this?
Here is the sample code I just created:
application, a popup menu will show up. If I move mouse outside the frame (I try to make JComponent visible so that I can move mouse outside JComponent, but I cannot make it happen), popup menu is still visible. I try to add the following to mouseExited method:
popupMenu.setVisible(false);
or add the following to let popup listen to mouse listener:
But these seemingly will disable pupup menu.
What I try to do is: make popup disappear once user move her mouse outside frame (better yet JComponent). How can I do this?
Here is the sample code I just created:
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Jack Mns
Greenhorn
Posts: 4
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks.
Just tried it. It seems popup does not disappear once mouse moved outside
the frame.
Just tried it. It seems popup does not disappear once mouse moved outside
the frame.
Originally posted by Craig Wood:
Craig Wood
Ranch Hand
Posts: 1535
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Craig Wood
Ranch Hand
Posts: 1535
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
If you are using j2se 1.5+ here is a way to keep the popupMenu visible until the mouse exits the underlying component or selects a JMenuItem on the menu, ie, so you can mouse in and out of the menu without losing it.
Jack Mns
Greenhorn
Posts: 4
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thank you very much, Craig. This works really nice.
But there is one problem though:
It works if popup menu is completely inside its parent component. If you
deliberately right-click on the very bottom of the frame, and let popup extends beyond the frame's bottom line, then move mouse down across popup menu til its below it. You can see popup still stays visible even though mouse is outside frame and popup.
It seems mouse still thinks its inside popup's parent component? or its a bug?
Or its a focus probelm: need to make popup lose focus once its moved outside both component/popup?
thanks,
[/qb]<hr></blockquote>
[ July 22, 2006: Message edited by: Jack Mns ]
But there is one problem though:
It works if popup menu is completely inside its parent component. If you
deliberately right-click on the very bottom of the frame, and let popup extends beyond the frame's bottom line, then move mouse down across popup menu til its below it. You can see popup still stays visible even though mouse is outside frame and popup.
It seems mouse still thinks its inside popup's parent component? or its a bug?
Or its a focus probelm: need to make popup lose focus once its moved outside both component/popup?
thanks,
[/qb]<hr></blockquote>
[ July 22, 2006: Message edited by: Jack Mns ]
Craig Wood
Ranch Hand
Posts: 1535
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Jack Mns
Greenhorn
Posts: 4
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks, Craig. It works like charm now.
Cheers!
Cheers!
| Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |






