Search code examples
javaswingmodal-dialogjlayeredpane

Java - disable DEFAULT_LAYER of JLayeredPane


I've got a JLayeredPane where my MODAL_LAYER is neatly covering the everything, and it's all generally going pretty well.

But there's a fly in the soup - the layers underneath still have functionality, even though they're visually hidden by the MODAL_LAYER.

Is there a neat way to "turn off" the lower layers, or pass all functionality to the MODAL_LAYER, or similar?

Seems like an easy question, maybe I'm having one of those moments.

EDIT

It may be possible to deny focus to any below layers, similar to JDialog, where nothing is allowed to happen except for direct interaction with the dialog?


Solution

  • You could use a glass pane and intercept events that don't go to a component of your modal layer. See http://docs.oracle.com/javase/tutorial/uiswing/components/rootpane.html