Colorizing strings in TreeViewer

How to color rows in TreeViewer?

It seems that there have been a couple of changes from the previous version, now we are moving on to Eclipse 3.4.

It would be great if you could provide sample code or point me to an open source project that does this.

+3
source share
1 answer

You can use ColumnLabelProvider with the overrideen method getBackground:

TreeViewerColumn column = new TreeViewerColumn(treeViewer, SWT.NONE);
column.getColumn().setText("Column name");
column.setLabelProvider(new ColumnLabelProvider() {
    @Override
    public String getText(Object element) {
        return element.toString();
    }

    @Override
    public Color getBackground(Object element) {
        return new Color(Display.getCurrent(), 0, 255, 0);
    }
});
+1
source

Source: https://habr.com/ru/post/1708746/


All Articles