Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse TableViewer set custom row background

How can a make my jface tableviewer display a chosen background color for specific rows? I have a timestamp in each row and like to give a row thats timestamp is on a monday a color, different than the others.

like image 979
Coxer Avatar asked Sep 02 '26 03:09

Coxer


1 Answers

With ColumnLabelProvider it is even easier:

col.setLabelProvider(new ColumnLabelProvider() {

@Override
public Color getBackground(final Object element) {
    if (element instanceof YourClass) {
        if (((YourClass) element).shouldBeRed()) {
            return new Color(Display.getDefault(), 0xFF, 0xDD, 0xDD);
        }
    }

    return super.getBackground(element);
}

});

Of course you should not create new colors on each getBackground but use resource managers for that purpose.

like image 72
Christian Avatar answered Sep 03 '26 19:09

Christian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!