Eclipse E4 CSS: Setting background to transparent on Label elements incorrectly renders as black in all themes
Let's make sure issue is not already fixed in latest builds first.
- [x] I verified I can reproduce this issue against latest Integration Build of Eclipse SDK (4.34.0)
Steps to reproduce
From a fresh installation and clean workspace:
- Create a simple eclipse plugin project based on wizard, uses view contribution 4.x API template
- For the view, create a composite which include two label
- Use css set the background for them
- For the composite, set any color (red) as the background
- For the labels, set background as transparent
I expected: Label elements to have transparent backgrounds that show the parent element's background color (red in this case)
But got: Label elements with solid black backgrounds regardless of parent background color or theme settings
Here is some relevant files
Codes of View
@PostConstruct
public void createPartControl(Composite parent) {
Composite test = new Composite(parent, SWT.BORDER);
test.setData("org.eclipse.e4.ui.css.CssClassName", "test");
test.setLayout(new GridLayout(1, false));
Label label = new Label(test, SWT.NONE);
label.setText("This is a label in a composite");
Label label2 = new Label(test, SWT.NONE);
label2.setText("This is a second label in a composite");
}
Codes for css
.test {
background: red !important;
background-color: red !important;
}
.test Label {
background: transparent !important;
background-color: transparent !important;
}
ScreenShot
Tested under this environment:
- OS & version: Mac OS 15.3
- Eclipse IDE/Platform version (as shown in Help > About): 2024-12
Community
- [x] I understand reporting an issue to this OSS project does not mandate anyone to fix it. Other contributors may consider the issue, or not, at their own convenience. The most efficient way to get it fixed is that I fix it myself and contribute it back as a good quality patch to the project.
What if you set a Label to transparent in code (not using CSS)? Is it also black?
What if you set a Label to transparent in code (not using CSS)? Is it also black?
I tried to use SWT.TRANSPARENT and SWT.NO_BACKGROUND, seems neither of them works, seems caused by https://github.com/eclipse-platform/eclipse.platform.ui/issues/306
Here are the codes
@PostConstruct
public void createPartControl(Composite parent) {
Composite test = new Composite(parent, SWT.BORDER);
// set parent background with css
test.setData("org.eclipse.e4.ui.css.CssClassName", "test");
test.setLayout(new GridLayout(1, false));
test.setBackground(new Color(255, 0, 0));
Label label = new Label(test, SWT.TRANSPARENT);
label.setText("This is a label in a composite");
label.setBackground(test.getBackground());
Label label2 = new Label(test, SWT.NO_BACKGROUND);
label2.setText("This is a second label in a composite");
label2.setBackground(test.getBackground());
}