I have an application that has a main GUI with a menubar, and another fullscreen frame, which makes some parts of the main GUI appear in fullscreen exclusive mode. When I am in fullscreen mode, I would like to bind a drop-down menu from the menu bar as jpopupmenu.
Swing provides the function getPopupMenu() in JMenu. This function seems to work fine at first glance. I can hover over the menuitems and move to and view the submenus. Hovering over the submenus does emphasize the submenus, hovering over a plain menuitem (or radiobuttonmenuitem or checkboxmenuitem) does not emphasize the item. However, I can’t actually click on a menuitem. The keyboard-shortcuts do actually work fine, though. The problem is essentially the same as presented on this forum (where the problem is not solved, though):
http://www.java-forums.org/new-java/16463-jmenu-jpopupmenu.html
If I add a JMenuItem after the menubar has been initialized and used/shown in the main GUI (thus when switching to the fullscreen frame), the menu-item is actually clickable. This menu-item is in turn also clickable in the menubar of the main GUI. Executing getPopupMenu() directly after initializing the jMenu does not change anything. Not using the fullscreen exclusive-mode does also not change anything about the problem.
Edit
It seems I left out some important information: I’m testing the app on Mac OSX and using:
System.setProperty("apple.laf.useScreenMenuBar", "true");
To make the menu bar use the native menubar. If I disable this, the popup-menu works as expected. This seems like a bug in the mac java API? Is their some way to overcome, this?
I apologize for forgetting mentioning this, I wasn’t aware this would influence anything (though it seems kind of obvious).
Okay, I’m probably missing something, but I hacked this together really quickly and have no issues
I apologies, I had to put it together while my 3 month old had a nap, so it’s quick and ugly 😛
UPDATE
After some playing around, it would seem that when we invoke the popup ourselves, I was changing the popup’s parent reference (
invoker) which meant that when theJMenutried to show the popup, the context was all wrong.I updated the
doActionPerformedmethod to look like this:Basically, resting the popup’s client reference.