jface alternating row background color [message #511346] |
Mon, 01 February 2010 07:03  |
Eclipse User |
|
|
|
Hi all,
I'd like to customize the alternating of background colors in a tableviewer, but getBackground of IColorProvider is called for each row cell, so the only way I found to do it is with the following code in my label provider:
public Color getBackground(Object element) {
// select the right color
Color colorToUseForThisRow = DEFAULT_BACKGROUND_NORMAL_COLOR;
if( element == null )
return colorToUseForThisRow;
// check if this element has a different hash code of the previous one
if( this.lastElementHashCode != element.hashCode() ){
this.lastElementHashCode = element.hashCode();
this.rowNumber++;
}
// decide which color to use for every row
if( this.rowNumber % 2 == 0 )
colorToUseForThisRow = DEFAULT_BACKGROUND_ODD_ROW_COLOR;
else
colorToUseForThisRow = DEFAULT_BACKGROUND_EVEN_ROW_COLOR;
// all done
return colorToUseForThisRow;
}
Is there a smarter way to achieve the same result? It will be nice to have an interface with a method called for each table row.
Thanks.
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.33635 seconds