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

[ListView] Wrong change events fire in ListView

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u25
    • Fix Version/s: 8u40
    • Component/s: javafx
    • Labels:
    • Environment:

      Windows 8.1

      Description

      In a ListView with multi-selection, when selecting items with shift-up from the last one, we get the following change events:
      --- select the last item (for example by clicking on the last item) OK ---
      { [One] replaced by [Four] at 0, }
      -- select both last items (with Shift-up keys OK ---
      { [Three] added at 0, }
      -- select the three last items (with Shift-up keys KO ---
      { [Four] removed at 3, } and { [Two, Three] added at 0, }


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

      public class ListViewChangeEvent extends Application {
      @Override
      public void start(Stage primaryStage) throws Exception {
      ObservableList<String> items = FXCollections.observableArrayList("One", "Two", "Three", "Four");
      ListView<String> listView = new ListView<String>(items);
      listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
      listView.getSelectionModel().getSelectedItems().addListener(new ListChangeListener<String>() {
      @Override
      public void onChanged(Change<? extends String> change) {
      System.out.println(change);
      }
      });
      VBox vBox = new VBox();
      vBox.getChildren().add(listView);
      Scene scene = new Scene(vBox);
      primaryStage.setScene(scene);
      primaryStage.show();
      }
      public static void main(String[] args) {
      Application.launch(args);
      }
      }

        Attachments

          Activity

            People

            Assignee:
            jgiles Jonathan Giles
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: