This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How do you setOpaque(false) on a JPopupMenu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How do you setOpaque(false) on a JPopupMenu" Watch "How do you setOpaque(false) on a JPopupMenu" New topic

How do you setOpaque(false) on a JPopupMenu

Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 650
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
Ranch Hand

Joined: Apr 01, 2009
Posts: 650
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.


rocket mass heater kickstarter
subject: How do you setOpaque(false) on a JPopupMenu