Skip to content

Commit 4b1ffac

Browse files
authored
🐛 Set the device selector component to opaque during its creation (#8471)
Fixes #8439 Fixes #7972 This is inspired by [StackOverflow](https://stackoverflow.com/questions/13939176/making-jcombobox-transparent), Claude Sonnet 4, and Gemini 2.5 Pro. Before: <img width="736" height="40" alt="image" src="https://github.com/user-attachments/assets/90afd256-19d9-4023-8401-5099d3e2a488" /> After: <img width="736" height="40" alt="image" src="https://github.com/user-attachments/assets/05b5d538-aa4d-4c86-b10d-2aba7c596dd3" />
1 parent bc2c099 commit 4b1ffac

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
- Resolved a "Slow operations are prohibited on EDT" exception on Flutter Project creation (#8446, #8447, #8448)
1212
- Made dev release daily instead of weekly
13+
- Set the device selector component to opaque during its creation to avoid an unexpected background color (#8471)
1314

1415
## 87.1.0
1516

src/io/flutter/actions/DeviceSelectorAction.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.intellij.openapi.util.Condition;
1919
import com.intellij.openapi.util.Key;
2020
import com.intellij.openapi.util.SystemInfo;
21+
import com.intellij.ui.JBColor;
2122
import com.intellij.util.ModalityUiUtil;
2223
import icons.FlutterIcons;
2324
import io.flutter.FlutterBundle;
@@ -29,6 +30,7 @@
2930
import org.jetbrains.annotations.Nullable;
3031

3132
import javax.swing.*;
33+
import java.awt.Component;
3234
import java.util.*;
3335

3436
public class DeviceSelectorAction extends ComboBoxAction implements DumbAware {
@@ -45,6 +47,39 @@ public class DeviceSelectorAction extends ComboBoxAction implements DumbAware {
4547
return ActionUpdateThread.BGT;
4648
}
4749

50+
@Override
51+
public @NotNull JComponent createCustomComponent(@NotNull Presentation presentation, @NotNull String place) {
52+
final JComponent component = super.createCustomComponent(presentation, place);
53+
// Set component to be transparent to match other toolbar actions
54+
component.setOpaque(false);
55+
// Update child components.
56+
updateComponentChildrenStyles(component);
57+
return component;
58+
}
59+
60+
private void updateComponentChildrenStyles(@NotNull JComponent parent) {
61+
final @Nullable Component[] children = parent.getComponents();
62+
if (children == null) {
63+
return;
64+
}
65+
66+
for (Component child : children) {
67+
if (child instanceof JComponent jComponent) {
68+
jComponent.setOpaque(false);
69+
70+
if (child instanceof JButton jButton) {
71+
jButton.setBorderPainted(false);
72+
jButton.setRolloverEnabled(true);
73+
// Make sure the button uses correct background & foreground.
74+
jButton.setBackground(JBColor.background());
75+
jButton.setForeground(JBColor.foreground());
76+
}
77+
78+
updateComponentChildrenStyles(jComponent);
79+
}
80+
}
81+
}
82+
4883
@Override
4984
protected @NotNull DefaultActionGroup createPopupActionGroup(@NotNull JComponent button, @NotNull DataContext dataContext) {
5085
final DefaultActionGroup group = new DefaultActionGroup();

0 commit comments

Comments
 (0)