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

[ListView] Removing multiple items including the selected item leads to inconsistent and wrong selection state

    XMLWordPrintable

    Details

      Description

      To reproduce:

      - add items "a","b","c","d"
      - select item "b"
      - remove items "b","c" using removeAll method

      expected:

      - getSelectedItem() returns "a", getSelectedIndex() returns 0
      - getSelectedItems().get(0) returns "a", getSelectedIndices().get(0) returns 0

      actual:

      - getSelectedItem() returns "b", getSelectedIndex() returns 1
      - getSelectedItems().get(0) returns null, getSelectedIndices().get(0) returns -1

      Test case to reproduce:

          @Test
          public void testListViewSelectionChanges() throws Exception {
              new JFXPanel();
              ListView<String> stringListView = new ListView<>();
              stringListView.getItems().addAll("a","b","c","d");
              stringListView.getSelectionModel().select("b");

              stringListView.getItems().removeAll("b","c");

              Assert.assertEquals(0, stringListView.getSelectionModel().getSelectedIndex());
              Assert.assertEquals(Integer.valueOf(0), stringListView.getSelectionModel().getSelectedIndices().get(0));
              Assert.assertEquals("a", stringListView.getSelectionModel().getSelectedItem());
              Assert.assertEquals("a", stringListView.getSelectionModel().getSelectedItems().get(0));
          }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jgiles Jonathan Giles
              Reporter:
              apabstjfx Andreas Pabst (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported: