rendered paste bodyimport org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
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 Main {
public static void main(String[] args) {
Display display= new Display();
Shell shell= new Shell(display);
final Color red= display.getSystemColor(SWT.COLOR_RED);
final Color yellow= display.getSystemColor(SWT.COLOR_YELLOW);
final Table table= new Table(shell, SWT.FULL_SELECTION);
table.setHeaderVisible(true);
table.setBackground(display.getSystemColor(SWT.COLOR_RED));
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) {
int clientWidth= table.getClientArea().width;
GC gc= event.gc;
Color oldForeground= gc.getForeground();
Color oldBackground= gc.getBackground();
gc.setForeground(red);
gc.setBackground(yellow);
gc.fillGradientRectangle(0, event.y, clientWidth, event.height, false);
gc.setForeground(oldForeground);
gc.setBackground(oldBackground);
event.detail&= ~SWT.SELECTED;
}
event.detail&= ~SWT.BACKGROUND;
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}