diff --git a/platform/platform-impl/src/com/intellij/internal/inspector/UiInspectorAction.java b/platform/platform-impl/src/com/intellij/internal/inspector/UiInspectorAction.java index a38ad020564d..a62e7a471af7 100644 --- a/platform/platform-impl/src/com/intellij/internal/inspector/UiInspectorAction.java +++ b/platform/platform-impl/src/com/intellij/internal/inspector/UiInspectorAction.java @@ -231,28 +231,37 @@ public class UiInspectorAction extends ToggleAction implements DumbAware { } private void setHighlightingEnabled(boolean enable) { - Component target = enable ? myComponent : myHighlightComponent; - JRootPane rootPane = target == null ? null : SwingUtilities.getRootPane(target); - JComponent glassPane = rootPane == null ? null : (JComponent)rootPane.getGlassPane(); - if (glassPane == null) { - myHighlightComponent = null; - return; - } - if (enable) { - myHighlightComponent = new HighlightComponent(new JBColor(JBColor.GREEN, JBColor.RED)); + if (myHighlightComponent != null) { + JComponent glassPane = getGlassPane(myHighlightComponent); + if (glassPane != null) { + glassPane.remove(myHighlightComponent); - Point pt = SwingUtilities.convertPoint(myComponent, new Point(0, 0), rootPane); - myHighlightComponent.setBounds(pt.x, pt.y, myComponent.getWidth(), myComponent.getHeight()); - glassPane.add(myHighlightComponent); - } - else { - glassPane.remove(myHighlightComponent); + glassPane.revalidate(); + glassPane.repaint(); + } myHighlightComponent = null; } - glassPane.revalidate(); - glassPane.repaint(); + + if (enable && myComponent != null) { + JComponent glassPane = getGlassPane(myComponent); + if (glassPane != null) { + myHighlightComponent = new HighlightComponent(new JBColor(JBColor.GREEN, JBColor.RED)); + + Point pt = SwingUtilities.convertPoint(myComponent, new Point(0, 0), glassPane); + myHighlightComponent.setBounds(pt.x, pt.y, myComponent.getWidth(), myComponent.getHeight()); + glassPane.add(myHighlightComponent); + + glassPane.revalidate(); + glassPane.repaint(); + } + } } + @Nullable + private static JComponent getGlassPane(@NotNull Component component) { + JRootPane rootPane = SwingUtilities.getRootPane(component); + return rootPane == null ? null : (JComponent)rootPane.getGlassPane(); + } } private static class ComponentTreeCellRenderer extends ColoredTreeCellRenderer {