Eclipse OwnerDrawLabelProvider makes background selection dark blue
I am currently developing an RCP Eclipse application and I need to use OwnerDrawLabelProvider as CellLabelProvider
for TableViewerColumn
This is because when I use others CellLabelProvider
, the image used is not centered.
My problem is that when a row is selected, the background of a cell that has this provider has a darker blue color than all the other cells.
This is what the "selected" state looks like:
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!
source to share
This is called by erase
the default method , the JavaDoc for this says:
Handle the erase event. The default is the background color of the selected areas with SWT.COLOR_LIST_SELECTION and the foreground color with SWT.COLOR_LIST_SELECTION_TEXT. Note that this implementation leads to non-native behavior on some platforms. Subclasses should override this method and not name the super implementation.
So, just add an override erase
that does nothing:
@Override
protected void erase(Event event, Object element)
{
// Don't call super to avoid selection draw
}
source to share