javaswingjframejlayeredpaneglasspane

Java Swing GlassPane functionality for individual panels?


I have built a simple interface that fills my entire JFrame. I am using a version of the class FinalGlassPane discovered on the internet here.

This glass pane has no regular event listeners, but it monitors the AWTEvents of it's underlying components. This way there is full functionality of the interface, and I can respond to global mouse movement coordinates with a single AWTEvent handler and paint on top of everything accordingly. Everything works great, but now I need a duplicate of this functionality, each with their own coordinate space and event handlers, inside the main JFrame. I just learned about JLayeredPane, but wanted to make sure this functionality would be possible with it. IE add a completely transparent but paintable JPanel layer on top, handle the AWTEvents with it, and still have underlying events fire normally.

EDIT: I am reading about using multiple JInternalFrame (and associated glass panes) inside of a JDesktopPane. I don't think JDesktopPane works with a layout manager, so I would have to absolutely position/resize the 2 frames when needed, but this may be the best option. END EDIT

Last thing I want to do is add mouse move listeners for every interface component and have to convert to parent panel coordinates to run the same method.

If I had to, I could keep monitoring the full glass pane mouse coordinates, and figure out how to branch the logic from there. Self contained and individualized would be better though.

And as one last caveat, I want to bring this to Android eventually, but know nothing about android graphics. If there is no layered panel functionality, I'd almost rather implement it the harder, more portable way first and once.


Solution

  • This can be accomplished by using JXLayer or JLayer if you're using Java 7. In General functionality of JXLayer/JLayer is superior to GlassPane.

    No Swing/AWT based solution will work on Android - you'd have to use Android specific component there.