/** * Sets a specified <code>Component</code> to be the glass pane for this root pane. The glass pane * should normally be a lightweight, transparent component, because it will be made visible when * ever the root pane needs to grab input events. * * <p>The new glass pane's visibility is changed to match that of the current glass pane. An * implication of this is that care must be taken when you want to replace the glass pane and make * it visible. Either of the following will work: * * <pre> * root.setGlassPane(newGlassPane); * newGlassPane.setVisible(true); * </pre> * * or: * * <pre> * root.getGlassPane().setVisible(true); * root.setGlassPane(newGlassPane); * </pre> * * @param glass the <code>Component</code> to use as the glass pane for this <code>JRootPane * </code> * @exception NullPointerException if the <code>glass</code> parameter is <code>null</code> */ public void setGlassPane(Component glass) { if (glass == null) { throw new NullPointerException("glassPane cannot be set to null."); } AWTAccessor.getComponentAccessor().setMixingCutoutShape(glass, new Rectangle()); boolean visible = false; if (glassPane != null && glassPane.getParent() == this) { this.remove(glassPane); visible = glassPane.isVisible(); } glass.setVisible(visible); glassPane = glass; this.add(glassPane, 0); if (visible) { repaint(); } }
/** * The <code>glassPane</code> and <code>contentPane</code> have the same bounds, which means * <code>JRootPane</code> does not tiles its children and this should return false. On the other * hand, the <code>glassPane</code> is normally not visible, and so this can return true if the * <code>glassPane</code> isn't visible. Therefore, the return value here depends upon the * visibility of the <code>glassPane</code>. * * @return true if this component's children don't overlap */ public boolean isOptimizedDrawingEnabled() { return !glassPane.isVisible(); }