Background:
I'm not sure why using transparent / semi-transparent backgrounds causes problems with heavyweight popups and how they paint, but it does -- regarless of whether or not you use AWTUtilities.setWindowOpaque(window, false)
or frame.setBackground(new Color(0, 0, 0, 0))
.
The HeavyWeightPopup
s get created when a popup can't fit all the way inside the target Window. So +User2280704 your problem also presents if you click at the very bottom of your window. LightWeightPopup
s do not have this problem -- hence, menus work in the middle of your window.
Also, interesting to note, typically the menu will render fine the first time, just not the following times.
Answer: I've come up with a workaround that invokes a repaint after any popups display. Simply invoke the following code when you launch your application.
PopupFactory.setSharedInstance(new PopupFactory()
{
@Override
public Popup getPopup(Component owner, final Component contents, int x, int y) throws IllegalArgumentException
{
Popup popup = super.getPopup(owner, contents, x, y);
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
contents.repaint();
}
});
return popup;
}
});