0

I am trying to populate my TreeView with several thousand items but when I go to open the new scene with the TreeView it takes around 3-6 minutes for it to finish populating and opening the new scene.

Here's the code im currently using.

       Platform.runLater(() -> {

            //populates indices with archives
            try {
                for (int index = 0; index < ...; index++) {

                    if(... > 0) {

                        int archives = ...;

                        for (int archive = 0; archive < archives; archive++) {
                            CacheTreeItem treeNode = new CacheTreeItem("folder " + archive);
                            rootNode.getChildren().get(finalMainFile).getChildren().get(index).getChildren().add(treeNode);

                            if(table != null && table.getEntry(archive) != null)
                                for(int child = 0; child < table.getEntry(archive).capacity(); child++) {
                                    CacheTreeItem treeNode2 = new CacheTreeItem("file " + child);
                                    rootNode.getChildren().get(finalMainFile).getChildren().get(index).getChildren().get(archive).getChildren().add(treeNode2);

                                }
                        }
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        });

Indices are around 40 files. Some archives are in the thousands and some of the children are in the hundreds. Is there a way to make this faster?

  • Take a look at the [infinite tree in by Jens-Peter Haack](http://stackoverflow.com/a/26796062/1155209) not how it adds children on demand (as tree branches are expanded by the user) rather than adding all children to the tree when the tree is created. Can you do this? – jewelsea Oct 14 '15 at 01:39
  • Your use of Platform.runLater is weird, you may wish to search the StackOverflow archives for Platform.runLater questions and learn from them. – jewelsea Oct 14 '15 at 01:39
  • @jewelsea I was thinking about adding the children when user expands the branch rather than all at once, as well. I'll look into that. thank you. – chrisalexander Oct 14 '15 at 01:41

0 Answers0