Search code examples
swingpopupsubmenu

Making JPopupMenu's submenus heavyweight


http://java.sun.com/products/jfc/tsc/articles/mixing/index.html advices how to make JPopupMenus heavyweight. Just set the property:

setLightWeightPopupEnabled(false);

It works fine, but if I have submenus in the popup, implemented as JMenu items, they don't seem to inherit the popup's heavy weight. JMenu doesn't have a method to make itself heavyweight, and using an AWT Menu isn't an option, since I want to put Swing items into it.

How do I make the submenus heavyweight, too?


Solution

  • It seems to be a Swing bug. Setting the global property

    JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    

    works! Also submenu JMenu items go heavy, as they should. Obviously the per-instance method setLightWeightPopupEnabled should work similarly, but it doesn't.

    I filed a bug (Bug Id: 7005406) on this, but I leave the question here just in case that someone else bumps on this. So the solution is to use the global setting until the bug gets fixed.