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

MultipleSelectionModel.getSelectedItems() does not fire proper list change event

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      A DESCRIPTION OF THE PROBLEM :
      MultipleSelectionModel.getSelectedItems() does not fire the expected number of list change events in certain cases, and the contents of those list change events is also incorrect.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Select all of the items in the TableView.
      2. Select 8 from the items in the TableView.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect a single list change event to be fired for this containing the following numbers: [0, 1, 2, 3, 4, 5, 6, 7, 9].
      ACTUAL -
      Instead, two list change events are fired: [0, 1, 2, 3, 4, 5, 6, 7] and [1].

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.collections.ListChangeListener;
      import javafx.scene.Scene;
      import javafx.scene.control.SelectionMode;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.stage.Stage;

      public class Main extends Application {

          @Override
          public void start(Stage primaryStage) {
              primaryStage.setTitle("Selection Model Bug");
              var tableView = new TableView<Integer>();
              var identityColumn = new TableColumn<Integer, String>();
              identityColumn.setCellValueFactory(integer -> new SimpleStringProperty(integer.getValue().toString()));
              tableView.getColumns().add(identityColumn);
              tableView.getItems().addAll(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
              tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
              tableView.getSelectionModel().getSelectedItems().addListener((ListChangeListener<Integer>) c -> {
                  while (c.next()) {
                      if (c.wasRemoved()) {
                          System.out.println(c.getRemoved());
                      }
                  }
              });
              primaryStage.setScene(new Scene(tableView, 300, 275));
              primaryStage.show();
          }


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

      FREQUENCY : always


        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated: