Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8093272

[TreeTableView] TreeTableView with fixedCellSize breaks virtualization

    XMLWordPrintable

Details

    Description

      If a fixedCellSize is set for the TreeTableView, the virtualization does not work any more: always new cells are created during scrolling.

      Main.java:
      import javafx.application.Application;
      import javafx.beans.property.ReadOnlyObjectWrapper;
      import javafx.scene.Scene;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeTableColumn;
      import javafx.scene.control.TreeTableView;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;


      public class Main extends Application {
          public static void main(String[] args) {
              launch(args);
          }
          
          @Override
          public void start(Stage primaryStage) {
        TreeTableColumn<String, String> myColumn = new TreeTableColumn<String, String>();
        myColumn.setPrefWidth(100);
        myColumn.setCellValueFactory((item)->(new ReadOnlyObjectWrapper<String>(item.getValue().getValue())));
        myColumn.setCellFactory((column)->new TTTVCell());
       
        TreeTableView<String> ttv = new TreeTableView<String>();
        ttv.setShowRoot(false);
        ttv.getColumns().add(myColumn);
       
        TreeItem<String> treeRootItem = new TreeItem<String>("root");
      treeRootItem.setExpanded(true);

      for (int i = 0; i < 100; i++) {
      treeRootItem.getChildren().add(new TreeItem<String>("Child: " + i));
      }

        ttv.setRoot(treeRootItem);
       
      // If a fixedCellSize is set for the TreeTableView,
      // the virtualization does not work any more:
        ttv.fixedCellSizeProperty().set(24);
              
              StackPane root = new StackPane();
              root.getChildren().add(ttv);
              primaryStage.setScene(new Scene(root, 300, 250));
              primaryStage.show();
          }
      }


      TTTVCell.java:
      import javafx.scene.control.TreeTableCell;

      public class TTTVCell extends TreeTableCell<String, String> {
      public TTTVCell() {
      super();
      System.out.println("Construct: " + getIndex() + " " + hashCode());
      }

      @Override
      protected void updateItem(String item, boolean empty) {
      super.updateItem(item, empty);
      if (item == null || empty){
      return;
      }
      setText(item);
      System.out.println("updateItem: " + getIndex() + " " + item + " " + hashCode());
      }
      }


      Output during Scrolling:
      Construct: -1 250363207
      updateItem: 30 Child: 30 250363207
      updateItem: 31 Child: 31 2006382679
      Construct: -1 1515939610
      updateItem: 31 Child: 31 1515939610
      updateItem: 32 Child: 32 503859464
      Construct: -1 415375129
      updateItem: 32 Child: 32 415375129
      updateItem: 33 Child: 33 382652579
      Construct: -1 423785265
      updateItem: 33 Child: 33 423785265
      updateItem: 34 Child: 34 1622266638
      Construct: -1 471510888
      updateItem: 34 Child: 34 471510888
      updateItem: 35 Child: 35 1164445846
      Construct: -1 1803409045
      updateItem: 35 Child: 35 1803409045
      updateItem: 36 Child: 36 504428626
      Construct: -1 1075628591
      updateItem: 36 Child: 36 1075628591
      updateItem: 37 Child: 37 1142713056
      Construct: -1 780341089
      updateItem: 37 Child: 37 780341089
      updateItem: 38 Child: 38 822456108
      Construct: -1 1864054892
      updateItem: 38 Child: 38 1864054892
      updateItem: 39 Child: 39 663229644
      Construct: -1 848378355
      updateItem: 39 Child: 39 848378355
      updateItem: 40 Child: 40 250363207
      ...and so on...

      Attachments

        Activity

          People

            jgiles Jonathan Giles
            jehrkejfx Jens Ehrke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: