Thanks to Mikle Garin for a great solution, you really helped me solve a similar problem! I would like to share my solution - based on Mikle - with a slight difference, which was significant in my case.
What I was looking for: transparent, undecorated windows behind JPopupMenu (my custom pop-ups are shown with a fancy speech border, so the window behind it should be invisible).
One thing that didn’t work very well with PropertyChangeListener: the view of the window is adjusted AFTER the window is displayed on the screen. On Mac OS X 10.10 with a java 8 window, a white background and a thin border (default L & F) are displayed behind the tooltip, and then it will be adjusted for a while (approximately 0.1 - 0.3 seconds) later. Pretty annoying.
After some time, when I put the setup code, I came up with the following simple solution: adjust the RIGHT window AFTER the menu is added to the window and BEFORE the window is displayed. The following example shows how to extend JPopupMenu to achieve this goal:
import java.awt.Color; import java.awt.Window; import javax.swing.JPopupMenu; import javax.swing.Popup; import javax.swing.RootPaneContainer; import javax.swing.SwingUtilities; import javax.swing.plaf.PopupMenuUI; public class MyPopup extends JPopupMenu { public MyPopup() { super();
In fact, the JPopupMenu extension is not required, but setting up a custom PopupMenuUI that causes the adjustment is important. Window customization code can be easily changed to meet specific needs and can be ported to a custom PopupMenuUI.
source share