I am trying to create a method that go through all nodes of a path. it will be used for a JTree and nodes will be files and folders. So it must go through the folders as well.
Here is my code:
Main setup:
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
final DefaultTreeModel treeModel = new DefaultTreeModel(root);
Search method:
public void search(TreePath path){
Object o = path.getLastPathComponent();
DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
o = node.getUserObject();
if(!node.isLeaf() && node.getChildCount() >= 0){
Enumeration e = node.children();
while (e.hasMoreElements()) {
search(path.pathByAddingChild(e.nextElement()));
}
}
else{
node = node.getNextNode();
}
}
So in my method I tied to specify if the node is a folder then go though it and follow the same process. otherwise get the next node and so on. But it does not work.
Any idea?