简体   繁体   English

JFace:在TreeViewer中更改TreeItem的颜色

[英]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: 我试图在运行时在包含TreeViewer的类中更改特定TreeNodes的BackgroundColor,但是它不起作用:

....
    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. 我想知道为什么这不起作用,因为TreeItem具有相应的方法。

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. 请注意,我不想为此使用Labelprovider,因为我必须检查节点之间的多个依赖关系以确定正确的Color,因此,Labelprovider不适合使用。

Cheers, Phil 干杯,菲尔

Check this example here . 在此处检查此示例。 For more examples on JFace see here . 有关JFace的更多示例, 请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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