diff --git a/platform/editor-ui-api/src/com/intellij/openapi/editor/colors/EditorColorsUtil.java b/platform/editor-ui-api/src/com/intellij/openapi/editor/colors/EditorColorsUtil.java index 1f51f943e716..a1a643cb482f 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/editor/colors/EditorColorsUtil.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/editor/colors/EditorColorsUtil.java @@ -15,6 +15,8 @@ */ package com.intellij.openapi.editor.colors; +import com.intellij.ide.ui.UISettings; +import com.intellij.ide.ui.UISettingsListener; import com.intellij.ui.ColorUtil; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; @@ -77,4 +79,22 @@ public class EditorColorsUtil { return colorsManager.isDarkEditor() ? colorsManager.getScheme(EditorColorsManager.DEFAULT_SCHEME_NAME) : colorsManager.getGlobalScheme(); } + + /** + * Use this method before showing a hidden component to make sure its LaF and colors are up-to-date. + * If a component was not reachable via Swing hierarchy and also was not reported via + * {@link UIUtil#NOT_IN_HIERARCHY_COMPONENTS}, its look-and-feel and colors need to be refreshed. + * + * @see com.intellij.util.ComponentTreeEventDispatcher + * @see UIUtil#NOT_IN_HIERARCHY_COMPONENTS + */ + public static void updateNotInHierarchyComponentUIAndColors(@Nullable Component component) { + if (component == null || component.isValid()) return; + for (Component o : UIUtil.uiTraverser(component).postOrderDfsTraversal()) { + if (o instanceof JComponent) ((JComponent)o).updateUI(); + if (o instanceof UISettingsListener) ((UISettingsListener)o).uiSettingsChanged(UISettings.getInstance()); + if (o instanceof EditorColorsListener) + ((EditorColorsListener)o).globalSchemeChange(EditorColorsManager.getInstance().getGlobalScheme()); + } + } }