Your previous example works great. I have one small difference is that I'm disabling the node instead of marking it grey with the hopes that you can't select it.
- Code: Select all
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
Component rendererComponent = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
TreePath path = tree.getPathForRow(row);
if (path != null && path.getPathCount() != 2 && !((CheckBoxTree) tree).getCheckBoxTreeSelectionModel().isPathSelected(path, true)) {
//rendererComponent.setForeground(Color.gray);
rendererComponent.setEnabled(false);
}
return rendererComponent;
}
The node does get disabled, but I have 2 issues
1) when it's disabled, the node doesn't render the file icon to the left of the node. When the checkbox is checked, and the nodes are enabled again, they get a file icon on the left.
Shouldn't the file icon be there in both cases?
2) when the node is disabled, I can still select the node, but the selection looks quite odd...