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

JavaFX ListView SelectionModel java.lang.IllegalStateException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8u20
    • 8u5
    • javafx
    • Mac OS X 10.9.2: jdk1.8.0_05. Windows: Reproducible with 8.0.0-b132, but not 2.2.45-b18.

      I have written a JavaFX sample that shows two ListViews side by side: The items of the right ListView are the selected items of the left ListView. The right ListView automatically tracks the selection changes of the first one.

      This works fine, but there is an exception when trying to extend the selection beyond the lower end of the list using the keyboard: Selecting the last item of the list and then Shift+ArrowDown leads to this exception:

      java.lang.IllegalStateException: Invalid Change state: next() must be called before inspecting the Change.


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

      public class rt36942 extends Application {

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

          public void start(Stage stage) {
              ObservableList<String> items = FXCollections.observableArrayList(
                      "Julia", "Ian", "Sue", "Matthew", "Hannah", "Stephan", "Denise");
              ListView<String> listView = new ListView<>(items);

              MultipleSelectionModel<String> selectionModel = listView.getSelectionModel();
              selectionModel.setSelectionMode(SelectionMode.MULTIPLE);
              ObservableList<String> selectedItems = selectionModel.getSelectedItems();

              ListView<String> selectedItemsListView = new ListView<>(selectedItems);

              HBox root = new HBox(5, listView, selectedItemsListView);

              Scene scene = new Scene(root, 500, 300);
              stage.setTitle("List View Sample");
              stage.setScene(scene);
              stage.show();
          }
      }

            jgiles Jonathan Giles
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: