Search code examples
javaswingalpha-transparencyjlayeredpaneglasspane

JLayeredPane with transparent layer causes incorrect drawing


I have a JLayeredPane that has two layers. The top level is fully transparent and acts as a glass pane that captures mouse events and then dispatches them to the pane beneath it. The bottom layer does not draw correctly for an unknown reason. Do I have to dispatch painting events to it or something else?

By the way, I would use the Frame's glass pane, but I cannot get at it. I am stuck using a JPanel that is provided by the GUI framework built on top of Swing. I tried using SwingUtilities to get at the parent frame, but it always returns null.


Solution

  • If you want to use a glasspane and capture Events in Swing use the JLayer (Java 7). If you do not use Java 7 you can use the JXLayer (http://java.net/projects/jxlayer/). This is the new swing default component for this behavior. See