I looked at the demo code, javadoc and at this forum but can't figure out how to disable a checkbox on a CheckBoxTree.
I created a CheckBoxTree and have the following DefaultTreeCellRenderer on it. I set the renderer using the method on CheckBoxTree. Most works as expected but the checkbox is NOT enabled. How do achieve that?
Thanks, Werner.
- Code: Select all
public class ImageLayerTypesListTreeCellRenderer extends DefaultTreeCellRenderer {
private static final String MAP_LEGEND_IMAGE_PATH = "../maplegend/icon.%s.png";
public Component getTreeCellRendererComponent(final JTree tree, final Object node, final boolean sel,
final boolean expanded, final boolean isLeaf, final int row, final boolean hasFocus) {
super.getTreeCellRendererComponent(tree, node, sel, expanded, isLeaf, row, hasFocus);
if (isLeaf && ((DefaultMutableTreeNode) node).getUserObject() instanceof ImageLayerTypeModel) {
ImageLayerTypeModel model = (ImageLayerTypeModel) ((DefaultMutableTreeNode) node).getUserObject();
final ImageIcon image = ImageUtilities.loadImageIcon(String.format(MAP_LEGEND_IMAGE_PATH,
model.getImageLayerType().name()), false);
setIcon(image);
setText(model.getImageLayerType().getFullName());
if(!model.isEnabled()) {
setEnabled(false);
setForeground(Color.gray);
}
}
return this;
}
}