the method getRoot() of interface javax.swing.tree.TreeModel returns an instance of class java.lang.Object. So the object returned is not necessarily an instance of class javax.swing.tree.TreeNode. Can you please post a working sample where we can reproduce your problem?
hi, here it is. this code displays the filesystem inside a jtree. just start it with some existing path like c:\. after 3 seconds a method is called and the exception occurs.....
what you have to do is distinguish between the types of nodes you click on... (leaf -> file, non-leaf -> directory). You could try using DefaultMutableTreeNode as a "wrapper" around your file-object. Just as a few suggestions...
my solution yould look something like this. What I did, is to wrap the File-objects in DefaultMutableTreeNodes. We have to do this to separate the model (the File-objects) from the view (the nodes of the JTree).
Stefan
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.