Setting JPanel colors has no effect in the toolwindow

Answered
        this.contentFactory = ContentFactory.getInstance();
        this.contentManager = toolWindow.getContentManager();

        JPanel jPanel = new JPanel(new BorderLayout());
        JLabel jLabel = new JLabel("hi, is my chat");
        jLabel.setOpaque(true);
        jLabel.setBackground(Color.RED);
        jPanel.setBackground(Color.RED);
        jPanel.add(jLabel, BorderLayout.CENTER);

        Content content = contentFactory.createContent(jPanel, "", false);
        contentManager.addContent(content);

How to solve the problem of color in the desired effect? Thank you

0
4 comments

Hi,

It is not possible to do by plugins.

Background of all components is overriden in https://github.com/JetBrains/intellij-community/blob/243/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.kt . See InternalDecoratorImpl.Companion#setBackgroundRecursively() calls. This is an internal API, and I don't see any way of disabling this behavior by plugins.

1

Make sure you're calling setBackground(@) on the correct component and that it's opaque (setOpaque(true)). ToolWindows may override styling.

0

Hi,

It is not possible to do by plugins.

Background of all components is overriden in https://github.com/JetBrains/intellij-community/blob/243/platform/platform-impl/src/com/intellij/openapi/drift boss/wm/impl/ToolWindowImpl.kt . See InternalDecoratorImpl.Companion#setBackgroundRecursively() calls. This is an internal API, and I don't see any way of disabling this behavior by plugins.

You’re correct setBackgroundRecursively() in ToolWindowImpl enforces the background styling at the platform level, and since it’s internal API there’s no supported extension point or override. At the plugin layer this behavior can’t be disabled or intercepted; the only options would be patching the platform itself or filing a feature request upstream.

0

IntelliJ themes can override Swing component colors. Make sure both the JPanel and JLabel are set to opaque(true), and try using JBPanel/JBLabel instead of standard Swing components. If it still doesn't show the expected red background, sharing a screenshot of the result would help identify what's overriding the color.

0

Please sign in to leave a comment.