i'm creeting a tree view for the file system....in order to assgin different icons to each node i'm overriding getTreeCellRendererComponent in the following manner
i have assigned a File object to each node using setUserObject()Code:public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel, boolean expanded, boolean leaf, int row,
boolean hasFocus) {
System.out.println("in cell renderer");
FileSystemView fsv=FileSystemView.getFileSystemView();
DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) value;
File nodefile=(File)dmtn.getUserObject();//i'm getting the below mentioned exception here
Icon icon;
String filename = "";
if (nodefile != null) {
if (ismynodefilesystem(nodefile)) {
if (filename == null) {
filename = fsv.getSystemDisplayName(nodefile);
}
} else {
filename = nodefile.getName();
}
}
JLabel result = (JLabel) super.getTreeCellRendererComponent(tree,
filename, sel, expanded, leaf, row, hasFocus);
if (nodefile != null) {
icon = fsv.getSystemIcon(nodefile);
result.setIcon(icon);
}
return result;
}
i'm getting an exception as:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.io.File
at line:File nodefile=(File)dmtn.getUserObject();
please help me with this code and do point out my mistakes
thanks

