I have a JTree and nodes of it are driven from DefaultMutableTreeNode. Each node can be verify or not.At first the icon of all nodes are the same but, I am going to change the ICON of the verified nodes when I select them and press the verify button.I want to have the ability to click and write on each node so I can not use JLabel to show icons. I made the following code but it returns NULLException.
class CustomIconRenderer extends DefaultTreeCellRenderer {
ImageIcon defaultIcon;
ImageIcon specialIcon;
ImageIcon closeIcon;
static DefaultTreeModel model;
static myDefaultMutableTreeNode root;
public CustomIconRenderer()
{
openIcon = new ImageIcon(CustomIconRenderer.class.getResource("icons/question.png"));
closeIcon = new ImageIcon(CustomIconRenderer.class.getResource("icons/Target-New-Logo.jpg"));
setLeafIcon(closeIcon);
}
@Override
public Component getTreeCellRendererComponent(JTree tree,Object value,boolean sel,boolean expanded,boolean leaf,int row,boolean hasFocus)
{
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
Object nodeObj = ((DefaultMutableTreeNode)value).getUserObject();
Check_each_nodes_are_verified_change_the_icon();
return this;
}
}
public class myDefaultMutableTreeNode extends DefaultMutableTreeNode{
private static int id=0;
private int nodeid;
private int verify;
private int depth;
}
Millions Thanks.