TreeView<String> a = new TreeView<String>();
a.setRoot(getNodesForDirectory(new File("C:")));
public TreeItem<String> getNodesForDirectory(File directory) { //Returns a TreeItem representation of the specified directory
TreeItem<String> root = new TreeItem<String>(directory.getName());
for(File f : directory.listFiles()) {
System.out.println("Loading " + f.getName());
if(f.isDirectory()) { //Then we call the function recursively
root.getChildren().add(getNodesForDirectory(f));
} else {
root.getChildren().add(new TreeItem<String>(f.getName()));
}
}
return root;
}