Project: SWT
Bug 328909 Setting foreground color in EraseItem listener has no effect
Reported: 2010-10-28 04:14:17 | Status: resolved fixed

Build Identifier: 3.7m2 See example below. The selected row should be drawn in red, but in 3.7m2 (unlike 3.6.1) the text is drawn in white, making the line appear 'blank'. Note that this bug affects the JFace features that allow the user to select a cell in the table (eg. FocusCellOwnerDrawHighlighter). Reproducible: Always Steps to Reproduce: import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; public class EraseItemExample { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Color red = display.getSystemColor(SWT.COLOR_RED); final Table table = new Table(shell, SWT.FULL_SELECTION); table.setHeaderVisible(true); new TableColumn(table, SWT.NONE).setWidth(100); new TableColumn(table, SWT.NONE).setWidth(100); new TableColumn(table, SWT.NONE).setWidth(100); for (int i = 0; i < 5; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(0, "item " + i + " col 0"); item.setText(1, "item " + i + " col 1"); item.setText(2, "item " + i + " col 2"); } table.pack(); table.addListener(SWT.EraseItem, new Listener() { public void handleEvent(Event event) { if ((event.detail & SWT.SELECTED) != 0) { event.gc.setForeground(red); event.detail &= ~SWT.SELECTED; } } }); shell.setSize(400, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }

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