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

IndexOutOfBoundsException when ListView clears selection on selection change

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Fix
    • P3
    • 8u20
    • 8u20
    • javafx
    • JavaFX 8u20 b05, Windows 7 x64

    Description

      Please see the sample application below. To reproduce, open it and select any item from the list.

      Note that in this setup it does not seem to make any sense to clear the selection right after the user selected something. The original error occured in a more complicated application, the code below is only the most simply way to reproduce it. This used to work in pre-8u20 versions. I think the error occurs since https://javafx-jira.kenai.com/browse/RT-35768 was fixed.


      import javafx.application.Application;
      import javafx.beans.InvalidationListener;
      import javafx.beans.Observable;
      import javafx.scene.Scene;
      import javafx.scene.control.ListView;
      import javafx.stage.Stage;

      public class ListViewSelectionChange extends Application {

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

          @Override
          public void start(Stage primaryStage) throws Exception {
              ListView<String> listView = new ListView<>();
              listView.getItems().addAll("Element 1", "Element 2", "Element 3");
              
              listView.getSelectionModel().getSelectedIndices().addListener(new InvalidationListener() {
                  public void invalidated(Observable observable) {
                      listView.getSelectionModel().clearSelection();
                  }
              });
               
              primaryStage.setScene(new Scene(listView));
              primaryStage.show();
          }

      }

      Attachments

        Activity

          People

            jgiles Jonathan Giles
            pkeckjfx Philipp Keck (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: