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

ListChangeListener getRemoved() returns items that were not removed.

XMLWordPrintable

    • b115
    • 9
    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "9.0.4"
      Java(TM) SE Runtime Environment (build 9.0.4+11)
      Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
      1

      ADDITIONAL OS VERSION INFORMATION :
      Linux proteus3 4.13.0-25-generic #29-Ubuntu SMP Mon Jan 8 21:14:41 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      ListChangeListener does not report correct items when using clearAndSelect on the selection model.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run example code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      +[zero, one, two]
      -[zero]
      -[two]

      ACTUAL -
      +[zero, one, two]
      -[zero]
      -[one]


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import static javafx.scene.control.SelectionMode.MULTIPLE;

      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.collections.FXCollections;
      import javafx.collections.ListChangeListener;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.ListView;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;


      public class Main extends Application {

          final ObservableList<String> listitems = FXCollections.observableArrayList("zero", "one", "two");

          @Override
          public void start(Stage primaryStage) {
              final ListView<String> lv = new ListView<>();
              lv.setItems(listitems);

              final HBox hbox = new HBox();
              hbox.getChildren().add(lv);
              primaryStage.setScene(new Scene(hbox));

              lv.getSelectionModel().setSelectionMode(MULTIPLE);
              lv.getSelectionModel().getSelectedItems().addListener((ListChangeListener<String>) ch -> {
                  while (ch.next()) {
                      if (ch.wasAdded()) {
                          System.out.println("+" + ch.getAddedSubList());
                      }
                      if (ch.wasRemoved()) {
                          System.out.println("-" + ch.getRemoved());
                      }
                  }
              });

              primaryStage.show();
              Platform.runLater(() -> lv.getSelectionModel().selectAll());
              Platform.runLater(() -> lv.getSelectionModel().clearAndSelect(1));
          }

          public static void main(String[] args) {
              Application.launch(args);
          }
      }

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

        1. Main.java
          2 kB
          Priyanka Mangal

            mstrauss Michael Strauß
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: