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

Error when combining ListView with SortedList

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 9
    • 8u60
    • javafx
    • x86_64
    • windows_7

    Description

      FULL PRODUCT VERSION :
      1.8.0_60, 1.8.0_66

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      When binding ListView items to a sorted list, changes in the sorted list lead to incorrect values in the ListView's list of selected items.


      REGRESSION. Last worked in version 8u45

      ADDITIONAL REGRESSION INFORMATION:
      1.8.0_40

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the code in the example below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The console output should be:

      2
      [2]
      ACTUAL -
      The console output is instead:

      2
      [1]

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      ListView<String> listView = new ListView<>();
      ObservableList<String> items = FXCollections.observableArrayList();
      SortedList<String> sortedItems = new SortedList<>(items);
      sortedItems.setComparator(String::compareTo);
      listView.setItems(sortedItems);

      items.add("2");
      listView.getSelectionModel().selectFirst();
      items.addAll("1", "3");

      System.out.println(listView.getSelectionModel().getSelectedItem());
      System.out.println(listView.getSelectionModel().getSelectedItems());
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Dont use items.addAll, use items.add repeatedly in a loop.





      Attachments

        Activity

          People

            jgiles Jonathan Giles
            webbuggrp Webbug Group
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: