Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse OwnerDrawLabelProvider makes selection background dark blue

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:

enter image description here

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!

like image 533
Vlad Ilie Avatar asked Oct 15 '25 09:10

Vlad Ilie


1 Answers

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
}
like image 133
greg-449 Avatar answered Oct 19 '25 14:10

greg-449