There are no built-in utilities for create a JTree model from a filesystem snippet. There is a file chooser if that is what you are after. Otherwise I would say that your approach seems reasonable to me. I would probably convert the files to a DefaultMutableTreeNode in one pass. Something like:
public class FileNode extends DefaultMutableTreeNode {
private File file;
public FileWrapper(File file) {
super(this);
this.file = file;
if(file.isDirectory()) {
for(File file : listFiles) {
add(new FileNode(file));
}
}
}
private String toString() {
return file.getName();
}
private File getFile() {
return file;
}
}