e4 CSS engine shouldn't overwrite colors explicitly set on controls using setForeground and/or setBackground
Colors set on widgets foreground and/or background does not work in Dark theme in Eclipse. It works just fine in Light/Classic. If colors are changed during various events later on (e.g. when user is processing the view or dialog box) to remove, set and/or change color, it seems to suddenly work if e.g. an entry field has received focus, but this cannot be a direct widget creation. I can't really see a pattern here, apart of entry field fore- and background being able to be set once the entry field (Text widget) has received focus.
Please find attached test case plugin with SWTColors view (open it in Eclipse using Views - Show view) along with dialog box showing the same thing. Also shows that flat toolbar items hovering color in dark theme is not really working.
Tested environment: Eclipse 4.25 M3, Java Temurin x64 18.0.2.1 under Windows 11 (with dark mode for system and apps).
Seems to be related to #259?
Below colors is initialized using:
Display display=parent.getDisplay();
colors=new Color []
{
new Color(display,255,127,127), // 0 - Red FG
new Color(display,127,255,127), // 1 - Green FG
new Color(display,127,127,255), // 2 - Blue FG
new Color(display, 95, 31, 31), // 3 - Red BG
new Color(display, 31, 95, 31), // 4 - Green BG
new Color(display, 31, 31, 95), // 5 - Blue BG
new Color(display,127,127,127), // 6 - Gray BG
};
Code creating widgets and setting colors looks like:
new Label(cnr,SWT.NONE).setText("Label:");
label=new Label(cnr,SWT.NONE);
label.setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,false));
label.setText("Label with red fore- and background");
label.setForeground(colors[0]);
label.setBackground(colors[3]);
new Label(cnr,SWT.NONE).setText("CLabel:");
CLabel clabel=new CLabel(cnr,SWT.NONE);
clabel.setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,false));
clabel.setImage(getDefaultImage());
clabel.setText("CLabel with red fore- and background");
clabel.setForeground(colors[0]);
clabel.setBackground(colors[3]);
new Label(cnr,SWT.NONE).setText("Text:");
Text text=new Text(cnr,SWT.SIMPLE|SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,false));
text.setText("Text with red fore- and background");
text.setForeground(colors[0]);
text.setBackground(colors[3]);
GridData gd=new GridData(SWT.FILL,SWT.FILL,true,true);
gd.heightHint=100;
new Label(cnr,SWT.NONE).setText("Text (area):");
text=new Text(cnr,SWT.MULTI|SWT.BORDER|SWT.WRAP|SWT.H_SCROLL|SWT.V_SCROLL);
text.setLayoutData(gd);
text.setText("Text area with red fore- and background");
text.setForeground(colors[0]);
text.setBackground(colors[3]);
new Label(cnr,SWT.NONE).setText("Combo:");
Combo combo=new Combo(cnr,SWT.DROP_DOWN);
combo.setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,false));
combo.setText("Combo with blue fore- and background");
combo.setForeground(colors[2]);
combo.setBackground(colors[5]);
for ( int ii=1; ii<4; ++ii )
combo.add("Line "+ii);
new Label(cnr,SWT.NONE).setText("CCombo:");
CCombo ccombo=new CCombo(cnr,SWT.DROP_DOWN|SWT.BORDER);
ccombo.setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,false));
ccombo.setText("CCombo with blue fore- and background");
ccombo.setForeground(colors[2]);
ccombo.setBackground(colors[5]);
for ( int ii=1; ii<4; ++ii )
ccombo.add("Line "+ii);
new Label(cnr,SWT.SEPARATOR|SWT.HORIZONTAL).setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,false,2,1));
new Label(cnr,SWT.NONE).setText("Button (press to open dialog box): ");
Button button=new Button(cnr,SWT.PUSH);
button.setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,false));
button.setText(" Button with blue fore- and background ");
button.setForeground(colors[2]);
button.setBackground(colors[5]);
button.addListener(SWT.Selection,(e)->new CustomDialog(parent.getShell()).open());
button.setFocus(); // Set focus to button.
new Label(cnr,SWT.NONE).setText("Checkbox:");
button=new Button(cnr,SWT.CHECK);
button.setText("Checkbox with green fore- and background");
button.setForeground(colors[1]);
button.setBackground(colors[4]);
new Label(cnr,SWT.NONE).setText("Radio button:");
button=new Button(cnr,SWT.RADIO);
button.setText("Radio button with green fore- and background");
button.setForeground(colors[1]);
button.setBackground(colors[4]);
new Label(cnr,SWT.SEPARATOR|SWT.HORIZONTAL).setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,false,2,1));
new Label(cnr,SWT.NONE).setText("Flat toolbar (check hovering mouse over)\nGray background");
ToolBar toolbar=new ToolBar(cnr,SWT.FLAT);
toolbar.setBackground(colors[6]); // Gray
ToolItem item=new ToolItem(toolbar,SWT.NONE);
item.setText("Red text - please check hover colors");
item.setForeground(colors[0]);
item.setBackground(colors[3]);
item=new ToolItem(toolbar,SWT.SEPARATOR);
item.setForeground(colors[2]);
item.setBackground(colors[5]);
item=new ToolItem(toolbar,SWT.DROP_DOWN);
item.setText("Blue combo");
item.setForeground(colors[2]);
item.setBackground(colors[5]);
item=new ToolItem(toolbar,SWT.PUSH);
item.setText(" Green push ");
item.setForeground(colors[1]);
item.setBackground(colors[4]);
item=new ToolItem(toolbar,SWT.CHECK);
item.setText("Green checkbox");
item.setForeground(colors[1]);
item.setBackground(colors[4]);
item=new ToolItem(toolbar,SWT.RADIO);
item.setText("Green radio button");
item.setForeground(colors[1]);
item.setBackground(colors[4]);
item=new ToolItem(toolbar,SWT.PUSH);
item.setText(" Plain button ");
item=new ToolItem(toolbar,SWT.DROP_DOWN);
item.setText("Plain combo");
new Label(cnr,SWT.SEPARATOR|SWT.HORIZONTAL).setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,false,2,1));
new Label(cnr,SWT.NONE).setText("Flat toolbar (check hovering mouse over)\nNo background");
toolbar=new ToolBar(cnr,SWT.FLAT);
item=new ToolItem(toolbar,SWT.NONE);
item.setText("Red text - please check hover colors");
item.setForeground(colors[0]);
item.setBackground(colors[3]);
item=new ToolItem(toolbar,SWT.SEPARATOR);
item.setForeground(colors[2]);
item.setBackground(colors[5]);
item=new ToolItem(toolbar,SWT.DROP_DOWN);
item.setText("Blue combo");
item.setForeground(colors[2]);
item.setBackground(colors[5]);
item=new ToolItem(toolbar,SWT.PUSH);
item.setText(" Green push ");
item.setForeground(colors[1]);
item.setBackground(colors[4]);
item=new ToolItem(toolbar,SWT.CHECK);
item.setText("Green checkbox");
item.setForeground(colors[1]);
item.setBackground(colors[4]);
item=new ToolItem(toolbar,SWT.RADIO);
item.setText("Green radio button");
item.setForeground(colors[1]);
item.setBackground(colors[4]);
item=new ToolItem(toolbar,SWT.PUSH);
item.setText(" Plain button ");
item=new ToolItem(toolbar,SWT.DROP_DOWN);
item.setText("Plain combo");