I'm currently developing an Eclipse RCP application, and am in need of using an OwnerDrawLabelProvider as a CellLabelProvider for a TableViewerColumn
This is because when I use any other CellLabelProvider, the Image used is not centered.
My problem is that when the row is selected, the background of the cell that has this provider is of a darker blue than all the other cells.
This is how the "selected" state looks:

Here's my OwnerDrawLabelProvider:
class SomeLabelProvider extends OwnerDrawLabelProvider {
private static final int smallColumnSize = 70;
@Override
protected void measure( Event event, Object element ) {
Rectangle rectangle = IMAGE_CHECKED.getBounds();
event.setBounds( new Rectangle( event.x, event.y, smallColumnSize,
rectangle.height ) );
}
@Override
protected void paint( Event event, Object element ) {
Rectangle bounds = event.getBounds();
//paint icon at the center
event.gc.drawImage( getImage( element ),
bounds.x + ((smallColumnSize -
IMAGE_CHECKED.getBounds().width) / 2),
bounds.y );
}
//this is implemented somewhere else
protected abstract Image getImage( Object element );
}
Thanks in advance!
This is caused by the default erase method, the JavaDoc for this says:
Handle the erase event. The default implementation colors the background of selected areas with SWT.COLOR_LIST_SELECTION and foregrounds with SWT.COLOR_LIST_SELECTION_TEXT. Note that this implementation causes non-native behavior on some platforms. Subclasses should override this method and not call the super implementation.
So just add an erase override which does nothing:
@Override
protected void erase(Event event, Object element)
{
// Don't call super to avoid selection draw
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With