Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

javafx treeview directory

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;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javafx #treeview #directory
ADD COMMENT
Topic
Name
1+4 =