Project: SWT
Bug 297633 [Widgets] Background of widgets in Group are incorrect
Reported: 2009-12-11 17:46:15 | Status: resolved fixed

When no background is set on widgets within a Group that has a parent whose BackgroundMode is SWT.INHERIT_DEFAULT, the widget's background appears to be the background of the parent. This is a cocoa-only regression. Windows displays it fine, as well as Carbon and Cocoa SWT 3.5 (and early Cocoa SWT 3.6). I'm currently seeing this bug with build 3624. Snippet: import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; public class testGroupBG { public static void main(String[] args) { Display display = new Display(); Color color = new Color(display, 180, 180, 200); Shell shell = new Shell(display, SWT.SHELL_TRIM); shell.setLayout(new FillLayout()); Composite c1 = new Composite(shell, SWT.NONE); c1.setLayout(new FillLayout()); c1.setBackground(color); c1.setBackgroundMode(SWT.INHERIT_DEFAULT); Composite c2 = new Composite(shell, SWT.NONE); c2.setLayout(new FillLayout()); c2.setBackgroundMode(SWT.INHERIT_DEFAULT); makeGroup(c1, "Group Test (BG)"); makeGroup(c2, "Group Test (No BG)"); shell.open(); while (!shell.isDisposed()) if (!display.readAndDispatch()) display.sleep(); } private static void makeGroup(Composite parent, String title) { Group group = new Group(parent, SWT.NONE); group.setText(title); group.setLayout(new RowLayout()); String s = "This is a line on SWT " + SWT.getPlatform() + "/" + SWT.getVersion(); for (int i = 0; i < 10; i++) { new Label(group, SWT.LEFT).setText(s); new Button(group, SWT.CHECK).setText("Checkbox"); } } } ==================== The first composite sets the color, and the result is both the label and the checkbox having the wrong background. The second composite doesn't set the background, and only the checkbox has the wrong background. If I remove the INHERIT_DEFAULT, it all works fine.

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Button.java bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Label.java