-
Hi, I have a control that needs to update its color when the user clicks it. However, it seems I can't change its color using CSS after it's been created. The code snippet: private void updateControlBackground(Control control, boolean selected) {
control.setData(UiConstants.E4_CSS_ID,
selected ? "quick-start-feature-card-selected" : "quick-start-feature-card");
control.redraw();
control.update();
if (control instanceof Composite) {
Composite composite = (Composite) control;
for (Control child : composite.getChildren()) {
updateControlBackground(child, selected);
}
}
} We also tried the following code (it didn't work) based on this post on Stack Overflow:
Instead, the private void updateControlBackground(Control control, boolean selected) {
// Force color update programmatically to override CSS
Color backgroundColor = selected ? new Color(Display.getCurrent(), 241, 241, 242) : // #F1F1F2
new Color(Display.getCurrent(), 255, 255, 255); // #FFFFFF
control.setBackground(backgroundColor);
// For Labels, also set foreground if needed
if (control instanceof Label) {
Color textColor = new Color(Display.getCurrent(), 0, 0, 0); // Black text
control.setForeground(textColor);
}
// Don't dispose colors immediately - store them for later disposal
control.setData("bg_color", backgroundColor);
// Add dispose listener to clean up colors
control.addDisposeListener(e -> {
Color bgColor = (Color) control.getData("bg_color");
if (bgColor != null && !bgColor.isDisposed()) {
bgColor.dispose();
}
});
if (control instanceof Composite) {
Composite composite = (Composite) control;
for (Control child : composite.getChildren()) {
updateControlBackground(child, selected);
}
}
} BTW, the control also includes Labels Any ideas? Thanks!" |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hi @iloveeclipse , could you please help us take a look of this issue? |
Beta Was this translation helpful? Give feedback.
-
Hi @sratz and @ptziegler , could you please help us take a look of this issue? Thanks. |
Beta Was this translation helpful? Give feedback.
@ethanyhou I'm by no means an expert in CSS, but isn't the issue simply that the class isn't updated recursively for all widgets?
i.e. this PoC seems to behave like your snippet with the hardcoded values: