eclipse.platform.ui icon indicating copy to clipboard operation
eclipse.platform.ui copied to clipboard

Eclipse E4 CSS: Setting background to transparent on Label elements incorrectly renders as black in all themes

Open Flanker32 opened this issue 10 months ago • 2 comments

Let's make sure issue is not already fixed in latest builds first.

Steps to reproduce

From a fresh installation and clean workspace:

  1. Create a simple eclipse plugin project based on wizard, uses view contribution 4.x API template
  2. For the view, create a composite which include two label
  3. Use css set the background for them
    1. For the composite, set any color (red) as the background
    2. 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

Image

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.

Flanker32 avatar Mar 06 '25 08:03 Flanker32

What if you set a Label to transparent in code (not using CSS)? Is it also black?

vogella avatar Mar 06 '25 09:03 vogella

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

Image

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());

	}

Flanker32 avatar Mar 07 '25 02:03 Flanker32