When I let popup a JPopupMenu without passing the "invoker component", the menu doesn't work: submenu's don't open and isn't getting repainted. But wh开发者_StackOverflow社区en I create a completely useless JFrame with a JLabel inside, and I pass the JLabal as invoker, it works correctly...
Any suggestions, how to avoid creating a useless frame. And my application really hasn't any frames open, it just has to popup a simple menu.
JPopupMenu.show(null, xOnTheScreen, yOnTheScreen); // Doesn't work
JPopupMenu.show(aStupidJLabelInAStupidJFrame, x, y); // Works
Thanks
Take a look at JPopupMenu
source code and you'll see why you have to set an invoker.
Showing a popup menu without any existing component would be very bad usability, in the same league as popup windows from a browser.
Why can't you use JComponent#setComponentPopupMenu
, or add a mouse listener to the component in which you want to show popup menu?
精彩评论