diff --git a/CHANGELOG.md b/CHANGELOG.md index 621624e468..edc1055a00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Resolved a "Slow operations are prohibited on EDT" exception on Flutter Project creation (#8446, #8447, #8448) - Made dev release daily instead of weekly +- Set the device selector component to opaque during its creation to avoid an unexpected background color (#8471) ## 87.1.0 diff --git a/src/io/flutter/actions/DeviceSelectorAction.java b/src/io/flutter/actions/DeviceSelectorAction.java index 2a0eb33b74..771d041c6b 100644 --- a/src/io/flutter/actions/DeviceSelectorAction.java +++ b/src/io/flutter/actions/DeviceSelectorAction.java @@ -18,6 +18,7 @@ import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.SystemInfo; +import com.intellij.ui.JBColor; import com.intellij.util.ModalityUiUtil; import icons.FlutterIcons; import io.flutter.FlutterBundle; @@ -29,6 +30,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; +import java.awt.Component; import java.util.*; public class DeviceSelectorAction extends ComboBoxAction implements DumbAware { @@ -45,6 +47,39 @@ public class DeviceSelectorAction extends ComboBoxAction implements DumbAware { return ActionUpdateThread.BGT; } + @Override + public @NotNull JComponent createCustomComponent(@NotNull Presentation presentation, @NotNull String place) { + final JComponent component = super.createCustomComponent(presentation, place); + // Set component to be transparent to match other toolbar actions + component.setOpaque(false); + // Update child components. + updateComponentChildrenStyles(component); + return component; + } + + private void updateComponentChildrenStyles(@NotNull JComponent parent) { + final @Nullable Component[] children = parent.getComponents(); + if (children == null) { + return; + } + + for (Component child : children) { + if (child instanceof JComponent jComponent) { + jComponent.setOpaque(false); + + if (child instanceof JButton jButton) { + jButton.setBorderPainted(false); + jButton.setRolloverEnabled(true); + // Make sure the button uses correct background & foreground. + jButton.setBackground(JBColor.background()); + jButton.setForeground(JBColor.foreground()); + } + + updateComponentChildrenStyles(jComponent); + } + } + } + @Override protected @NotNull DefaultActionGroup createPopupActionGroup(@NotNull JComponent button, @NotNull DataContext dataContext) { final DefaultActionGroup group = new DefaultActionGroup();