Custom colors in installed SWT Controls example view are overwritten by themeing
Describe the bug In SWT controls, setting both foreground and background colours on a widget does not work as expected. Changing one colour causes the other to reset or disappear.
To Reproduce
- Install SWT Controls via:
- Help → Install New Software → Select Eclipse SDK Examples → Install it.
- Launch the SWT Controls.
- Open any widget tab (e.g., Button, Label, or List).
- Try to change the background colour of the widget – it updates as expected.
- Then, change the foreground colour.
Expected behaviour Both foreground and background colours should be applied together and retained simultaneously on the widget.
Observed behaviour
- When the foreground colour is changed, the previously set background color is lost
- Similarly, if you set the foreground colour first, and then change the background, the foreground colour disappears.
- In both cases, only one colour (foreground or background) is retained at a time.
Environment:
- Select the platform(s) on which the behavior is seen:
-
- [ ] All OS
-
- [ ] Windows
-
- [ ] Linux
-
- [x] macOS
- Additional OS info (e.g. OS version, Linux Desktop, etc)
Workaround (or) Additional context Not known
Is the bug in the SWT Control Example code or in SWT itself?
Is the bug in the SWT Control Example code or in SWT itself?
I don't see the bug in the control example code present in package org.eclipse.swt.examples.controlexample. This is seen with the SWT controls and SWT custom controls installed via Help-> install new software -> Eclipse SDK Examples
I was able to reproduce the described behavior, but it's actually a bit different than described. Yes, you cannot change background and foreground color at the same time. But it's nothing between these two kinds of colors but it's because when the view received focus again (just by clicking into it), the just set color is overwritten. You can already reproduce this with changing background or foreground color: do the change, click into the view and you will see that the color is restored.
But this is kind of expected behavior: it comes from the application themeing. When you disable theming for your application, the colors remain as selected. So it's actually an interaction issue of the SWT control example and their way of recoloring with the themeing of Eclipse.
In my opinion, this is not worth being considered as an issue, so I would vote for closing this as "not planned". But if you want to work on it, of course feel free to keep it open. I just changed the title to avoid confusion.
In my opinion, changing the background / foreground colors of a component in an individual basis should be honored. What about overriding the CSS values provided by the theme for this component only ?
In my opinion, changing the background / foreground colors of a component in an individual basis should be honored.
I understand the expectation and agree that an API user will probably exactly that. In my understanding this is not how it currently works and, technically, it may also be quite difficult to achieve that as the CSS engine is not integrated into SWT but implemented on top in the Eclipse platform and just uses API to change background/foreground colors just like any other consumer that does that manually. One would need to find a way to identify in the CSS engine that a custom color was set to a control so that CSS styling should not be applied there. In any case, that would need to be done in Eclipse platform's CSS engine.
What about overriding the CSS values provided by the theme for this component only ?
That might be possible. I am not sure whether using the SWT control example view is such an important use case that someone wants to invest time into contributing such a customization. But in case someone wants to do that, it could be a way to go.