Here you can find the source of setGlassPane(JComponent comp, Component glass, boolean visible)
public static void setGlassPane(JComponent comp, Component glass, boolean visible)
//package com.java2s; //License from project: LGPL import java.awt.Component; import java.awt.Container; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JFrame; public class Main { public static void setGlassPane(JComponent comp, Component glass, boolean visible) { Container container = comp.getTopLevelAncestor(); if (container instanceof JFrame) { JFrame frame = (JFrame) container; frame.setGlassPane(glass);/*from w ww. j ava 2 s . c om*/ } else if (container instanceof JDialog) { JDialog dialog = (JDialog) container; dialog.setGlassPane(glass); } else { throw new RuntimeException("unsupported top level ancestor!"); } glass.setVisible(visible); } }