开发者

Java: Show JPopupMenu without passing an invoker component

开发者 https://www.devze.com 2023-01-18 11:53 出处:网络
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 comple

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号