I have a swing app with lots of components and stuff. I want to place a Container/Jpanel on top of everyting else that is invisible that contains other component which are visible.

I can make the panel invisible or not opaque and still show its child component but I also want the panel not to block events to underlying component. For example there is a button under the panel, the button is visible, but it can't be clicked since the panel is in the way.

How do I make it so that panel doesn't block underlying components from receiving input?



5 Years
Discussion Span
Last Post by mKorbel

I haven't and I can't. We don't want to migrate to java 7 yet. Not my decision. Is there a way to do it in java 6?


there are two ways

1) create once JWindow/JDialog and re-use that, JDialog#setModal(true) block all user inputs except ALT-F4

2) implements GlassPane

Edited by mKorbel: n/a


I found another way. You can override the contains(Point p) method of JComponent to return false all the time, or make another implementation that takes the children of the component into consideration, but not itself.

I not sure if its a very good solution but it works and is very easy to implement.


sure is possible and using JComponent instead of JPanel is great idea,

I think that 5 layers should be sufficient number of

check API for SwingUtilities, because returns in all cases correct value for Point, getAncesor, getChilden especially getDeepestComponentAt (I wrote there methods from head without seeing API from fat_handy/cellmobile)


JPanel extends JComponent so it works for JPanel as well. Almost all swing component extends JComponent.


not I not meaning to use JPanel, not JLabel, using directly JComponent, be sure that is very funny Container

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.