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

Removing TreeItem from a TreeTableView sometime changes selectedItem

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_152"
      Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux asus14 4.4.0-103-generic #126-Ubuntu SMP Mon Dec 4 16:23:28 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      Removing one TreeItem from a TreeTableView changes TreeTableView selectedItem.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the following javafx program:
      ----------------------------------------------------
      package sample;

      import javafx.application.Application;
      import javafx.beans.property.ReadOnlyStringWrapper;
      import javafx.scene.Scene;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeTableColumn;
      import javafx.scene.control.TreeTableView;
      import javafx.stage.Stage;

      public class Main extends Application {

          @Override
          public void start(Stage primaryStage) throws Exception{
              TreeItem<String> rootNode = new TreeItem<String>("Root");
              rootNode.setExpanded(true);
              for (int i = 0; i < 3; i++) {
                  rootNode.getChildren().add(new TreeItem<>("Node " + i));
              }
              for (int i = 0; i < 2; i++) {
                  TreeItem<String> node = rootNode.getChildren().get(i);
                  node.setExpanded(true);
                  for (int j = 0; j < 2; j++) {
                      node.getChildren().add(new TreeItem<>("Sub Node " + i + "-" + j));
                  }
              }

              TreeTableColumn<String, String> column = new TreeTableColumn<>("Nodes");
              column.setCellValueFactory((TreeTableColumn.CellDataFeatures<String, String> p) -> {
                  return new ReadOnlyStringWrapper(p.getValue().getValue());
              });
              column.setPrefWidth(200);

              TreeTableView<String> table = new TreeTableView<>(rootNode);
              table.getColumns().add(column);

              int selectIndex = 4; // select "Node 1"
              int removeIndex = 2; // remove "Node 2"
              table.getSelectionModel().select(selectIndex);
              System.out.println("Selected index = " + table.getSelectionModel().getSelectedIndex());
              System.out.println("Selected item = " + table.getSelectionModel().getSelectedItem().getValue());
              table.getRoot().getChildren().remove(removeIndex);
              System.out.println("Selected index = " + table.getSelectionModel().getSelectedIndex());
              System.out.println("Selected item = " + table.getSelectionModel().getSelectedItem().getValue());

              primaryStage.setTitle("Tree Table View Selection");
              primaryStage.setScene(new Scene(table, 300, 275));
              primaryStage.show();
          }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Selected index = 4
      Selected item = Node 1
      Selected index = 4
      Selected item = Node 1
      ACTUAL -
      Selected index = 4
      Selected item = Node 1
      Selected index = 3
      Selected item = Sub Node 0-1

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package sample;

      import javafx.application.Application;
      import javafx.beans.property.ReadOnlyStringWrapper;
      import javafx.scene.Scene;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeTableColumn;
      import javafx.scene.control.TreeTableView;
      import javafx.stage.Stage;

      public class Main extends Application {

          @Override
          public void start(Stage primaryStage) throws Exception{
              TreeItem<String> rootNode = new TreeItem<String>("Root");
              rootNode.setExpanded(true);
              for (int i = 0; i < 3; i++) {
                  rootNode.getChildren().add(new TreeItem<>("Node " + i));
              }
              for (int i = 0; i < 2; i++) {
                  TreeItem<String> node = rootNode.getChildren().get(i);
                  node.setExpanded(true);
                  for (int j = 0; j < 2; j++) {
                      node.getChildren().add(new TreeItem<>("Sub Node " + i + "-" + j));
                  }
              }

              TreeTableColumn<String, String> column = new TreeTableColumn<>("Nodes");
              column.setCellValueFactory((TreeTableColumn.CellDataFeatures<String, String> p) -> {
                  return new ReadOnlyStringWrapper(p.getValue().getValue());
              });
              column.setPrefWidth(200);

              TreeTableView<String> table = new TreeTableView<>(rootNode);
              table.getColumns().add(column);

              int selectIndex = 4; // select "Node 1"
              int removeIndex = 2; // remove "Node 2"
              table.getSelectionModel().select(selectIndex);
              System.out.println("Selected index = " + table.getSelectionModel().getSelectedIndex());
              System.out.println("Selected item = " + table.getSelectionModel().getSelectedItem().getValue());
              table.getRoot().getChildren().remove(removeIndex);
              System.out.println("Selected index = " + table.getSelectionModel().getSelectedIndex());
              System.out.println("Selected item = " + table.getSelectionModel().getSelectedItem().getValue());

              primaryStage.setTitle("Tree Table View Selection");
              primaryStage.setScene(new Scene(table, 300, 275));
              primaryStage.show();
          }

      ---------- END SOURCE ----------

        Attachments

          Issue Links

            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: