1

I tried to change the BackgroundColor of specific TreeNodes during runtime inside my Class which contains my TreeViewer, but it doesn't work:

....
    Display display = Display.getCurrent();
            for (TreeItem item : treeItems) {
                if (item.getParentItem() != null) {
                    Object parentElement = item.getParentItem().getData();
                    if(parentElement instanceof Or){
                        System.out.println(item);
                        Color color = new Color(display,12, 197, 77);
                        item.setBackground(color);
                        item.setForeground(color);
                    }
                }
            }
  ......

I'm wondering why this doesn't work, as TreeItem has the according methods for this.

Note that I don't want to use my Labelprovider for this, as I've to check several dependencies between nodes to determine the right Color and therefor, the Labelprovider don't fit in.

Cheers, Phil

ph09
  • 1,052
  • 2
  • 20
  • 31
  • If you don't want to use LabelProvder you should not use TreeViewer as it will be consulting the label provider all the time. Just use the SWT Tree. It is perfectly straightforward to do this in a label provider. You must also call `dispose` for Color object you create. – greg-449 Nov 13 '13 at 12:38
  • I want to use the labelprovider, but not for everything. So the Labelprovider will overwrite my item.setBackground(color) thenand set it to the default color? And how have I to call dispose? – ph09 Nov 13 '13 at 13:28

1 Answers1

0

Check this example here. For more examples on JFace see here.

Chandrayya G K
  • 8,719
  • 5
  • 40
  • 68