views:

1996

answers:

3

In a elipse-rcp application I am setting the background color for a row in a jface table but I don't want the selection to change this color. I want to be able to specify the color change for a selected row.

+2  A: 
VonC
Thanks VonC. Using the code from the above example I was able to do what I wanted.
ks
A: 
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet129.java

may be helpful here

Ben Hammond
+1  A: 
table.addListener(SWT.EraseItem, new Listener() {
public void handleEvent(Event event) {
 event.detail &= ~SWT.HOT;
 if ((event.detail & SWT.SELECTED) == 0) return; /// item not selected

 Table table =(Table)event.widget;
 TableItem item =(TableItem)event.item;
 int clientWidth = table.getClientArea().width;

 GC gc = event.gc;    
 Color oldForeground = gc.getForeground();
 Color oldBackground = gc.getBackground();

 gc.setBackground(colorBackground);
 gc.setForeground(colorForeground);    
 gc.fillRectangle(0, event.y, clientWidth, event.height);

 gc.setForeground(oldForeground);
 gc.setBackground(oldBackground);
 event.detail &= ~SWT.SELECTED;
}

});

ks
@ks: thank you for that feedback. +1. You could choose your own post as the official answer if you want
VonC