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

Collapsing row outside of viewport with navigation key makes TreeTableView blank

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: openjfx11, openjfx14
    • Fix Version/s: tbd
    • Component/s: javafx
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10 / jdk11.0.1

      A DESCRIPTION OF THE PROBLEM :
      Given a TreeTableView with several rows and children, when a row with children is expanded while it's not visible because the user scrolled, when the row is collapsed using the left navigation key, then the TreeTableView goes blank.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      - On a TreeTableView, select a child row (i.e: "child1" from SSCCE) and expand it using right navigation key
      - Keep the selection on that row and scroll down to the bottom of the table. The "child1" row is still selected and expanded but not visible
      - Use left navigation key to collapse "child1"

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The row should collapse and the table should continue to displays the rows we were looking at after the scroll.
      ACTUAL -
      The table goes blank, the rows are not visible anymore. If the user scrolls the rows appear again.

      ---------- BEGIN SOURCE ----------

      public class CollapseBug extends Application {
          @Override
          public void start(Stage stage) {
              stage.setScene(new Scene(new StackPane(createTree()), 800, 500));
              stage.show();
          }

          private Node createTree() {
              TreeTableView<String> treeTable = new TreeTableView<>();
              treeTable.setMinWidth(500);
              TreeTableColumn<String, String> column = new TreeTableColumn<>("column");
              column.setMinWidth(500);
              treeTable.getColumns().add(column);
              column.setCellValueFactory(value -> new SimpleStringProperty(value.getValue().getValue()));

              treeTable.setOnKeyPressed(event -> {
                  ObservableList<TreeTablePosition<String, ?>> selectedCells = treeTable.getSelectionModel().getSelectedCells();
                  if (!selectedCells.isEmpty()) {
                      int row = selectedCells.get(0).getRow();
                      VirtualFlow<?> virtualFlow = getVirtualFlow(treeTable);
                      if (virtualFlow != null && virtualFlow.getFirstVisibleCell() != null) {
                          int first = virtualFlow.getFirstVisibleCell().getIndex();
                          int last = virtualFlow.getLastVisibleCell().getIndex();
                          if (row < first || row > last) {
                              System.out.println(row + " is outside visible rows [" + first + ";" + last + "]");
      // treeTable.refresh(); // Uncomment this line for the workaround to work
                          }
                      }
                  }
              });

              return createData(treeTable);
          }

          private TreeTableView<String> createData(TreeTableView<String> treeTable) {
              TreeItem<String> root = new TreeItem<>("root");
              treeTable.setRoot(root);
              for (int i = 0; i < 50; i++) {
                  root.getChildren().add(new TreeItem<String>("child" + i));
                  for (int j = 0; j < 50; j++) {
                      root.getChildren().get(i).getChildren().add(new TreeItem<String>("child" + i + "." + j));
                  }
              }
              return treeTable;
          }

          private VirtualFlow<?> getVirtualFlow(TreeTableView<?> table) {
              return (VirtualFlow<?>)((TreeTableViewSkin<?>)table.getSkin()).getChildren().get(1);
          }

          public static void main(String[] args) {
              launch(args);
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      In the SSCCE provided, I do a treeTable.refresh() when the collapse event occurs outside of the visible rows. It seems to fix the bug (tested with JavaFx 11.0.2, 14.0.1 and 15-ea+4)
      Sometimes it requires a few tries spamming left & right arrow keys to reproduce the issue, sometimes it is reproduced on first try.

      FREQUENCY : often


        Attachments

          Activity

            People

            • Assignee:
              aghaisas Ajit Ghaisas
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: