aspose file tools*
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
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
Author

How do you setOpaque(false) on a JPopupMenu

Mark E Hansen
Ranch Hand

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

Thanks,

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do you setOpaque(false) on a JPopupMenu
 
Similar Threads
How to make popup invisible
Mouse click getting lost after popping up a non-modal JPopupMenu
JPopup That Looks Like ToolTip
JPanel Transparent does not work with setO
Prevent JPopupMenu from hiding when clicked outside the menu