JLayeredPane (Window window) { if (window instanceof JFrame) { return ((JFrame) window).getRootPane().getLayeredPane(); } else if (window instanceof JDialog) { return ((JDialog) window).getRootPane().getLayeredPane(); } return null; }