我想禁用(仅虚拟)树查看器中的某些特定节点,但它似乎对我的节点没有影响。我还尝试设置一个背景,但也不起作用。对此有什么想法吗?
private void setSelectedElements(TreeItem[] treeItems) {
for (TreeItem item : treeItems) {
Object obj = item.getData();
if (item.getParentItem() != null) {
Object parentElement = item.getParentItem().getData();
if (parentElement instanceof Mandatory) {
setChecked(item);
Display display = Display.getCurrent();
item.setGrayed(true);
item.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
}
}
setSelectedElements(item.getItems());
}
}
最佳答案
setGrayed
用于更改复选框树或表中复选框的状态。它不会改变树项目的颜色。来自 setGrayed
的 JavaDoc:
Sets the grayed state of the checkbox for this item. This state change only applies if the Tree was created with the SWT.CHECK style.
如果您想更改树项目的颜色,请使用实现 IColorProvider
的 LabelProvider
或从 StyledCellLabelProvider
派生的标签提供程序。
关于java - JFace:Setgrayed 在树查看器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19939577/