0

I'm using JavaFX/OpenJFX for GUI in Java, and need to populate TreeTableView with millions of items. However, it currently takes a very long time to do it. Is there a way to speed it up?

Here is my code:

List<TreeItem<FeatureTableItem>> rootChildren = treeTableView.getRoot().getChildren();
rootChildren.clear();
for (Feature feature : features) {
    TreeItem<FeatureTableItem> featureItem = new TreeItem<>(feature);
    rootChildren.add(featureItem);
}
aleksmath
  • 3
  • 1
  • 3
  • 4
    The use of GUI indicates that the data is intended for humans. In reality, however, one cannot process millions of rows in tabular form. This means that the very approach to working with data is wrong. – mr mcwolf Jul 13 '21 at 13:28

1 Answers1

4

Build a separate List, and instead of using rootChildren.clear() and rootChildren.add, use setAll.

Each time you modify the list of children, the TreeTableView has to update its own layout. By using setAll, you will cause the TreeTableView do that once, instead of millions of times.

List<TreeItem<FeatureTableItem>> rootChildren = new ArrayList<>();
for (Feature feature : features) {
    TreeItem<FeatureTableItem> featureItem = new TreeItem<>(feature);
    rootChildren.add(featureItem);
}

treeTableView.getRoot().getChildren().setAll(rootChildren);
VGR
  • 40,506
  • 4
  • 48
  • 63
  • 2
    Thank you for your answer. I've tried using `setAll()` but it was still too slow. I actually ended up switching to `TableView` after removing some functionality. `TableView` is so much faster than `TreeTableView`. – aleksmath Jul 14 '21 at 14:17