This article describes how to make the colors of user interface components in IntelliJ adaptable to changes in the IDE theme.
Create a UI Component
Suppose we now have a component like this
We set a background color for the UIContainer that comes from the current ColorsScheme’s NOTIFICATION_BACKGROUND,
but it’s clear that in this case, when we switch themes, the color of the UIContainer doesn’t switch with the theme’s color.
UIContainer color doesn’t switch with the theme’s color when we switch themes in this case. However, in most cases,
this may cause the UI to have similar colors and fonts, so that the displayed content is not visible.
So, how can we make the background color of UIContainer change automatically as the theme changes?
Adaptive to IDE theme
Implements Interfaces
Make UIContainer implements Disposable and EditorColorsListener
Add Message Event
Implements globalSchemeChange
When theme changed, the globalSchemeChange method will be called.
currentColorsScheme will be the selected theme, so we regain the notificationColor
from currentColorsScheme and reset the color for the component.
Implements dispose
Finally Code
So, The final code is as follows
Now when you switch themes, the color of the component will automatically change with the color of the theme. Hope this helps.