简体   繁体   中英

JFace: Change Color of TreeItem in TreeViewer

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM