I'm using Java JDK 1.6.0_18 (64-bit) on a Windows 7 (64-bit) machine.
I have a Swing application which needs to pop-up a JPopupMenu that contains a simple JPanel. The final JPanel will have a border drawn on it based on a theme chosen by the user. As such, I need the JPopupMenu to be transparent (setOpaque(false)), but can't get it to work. I've called setOpaque(false) on the popup menu, as well as the JPanel I'm adding to it, but still the popup is not transparent.
I've heard that when the JPopupMenu is using heavyweight components, you just can't make it transparent, and am wondering if that is my problem.
I ran through a loop of getParent() starting with the pop-up menu (once it was made visible) and see the following:
The pop-up menu's parent is a JPanel
whose parent is a JLayeredPane
whose parent is a JRootPane
whose parent is a Popup$HeavyWeightWindow
whose parent is a Popup$DefaultFrame
whose parent is null.
Does this mean my JPopupMenu is a heavy weight component? If so, why is it? My pop-up is placed in the middle of the application, well within its bounds (not hanging over the edge). I have not called setLightWeightPopupEnabled( false ) or setDefaultLightWeightPopupEnabled( false )
I read that once the JPopupMenu is visible, that I will need to get the parent (JPanel) and call setOpaque(false) on this. I've done that, but the pop-up is still not transparent. Is there another component in there that needs to have setOpaque(false) called on it?
Thanks for any help.
Mark E Hansen
Joined: Apr 01, 2009
Well, it seems the problem was that I was calling setVisible(true) on the JPopupMenu, rather than show(Component, x, y).
Now that I'm calling show() and as long as the pop-up is supposed to display within the application's main frame, it is transparent as desired.