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

JavaFX ListView SelectionModel java.lang.IllegalStateException

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u5
    • Fix Version/s: 8u20
    • Component/s: javafx
    • Environment:

      Mac OS X 10.9.2: jdk1.8.0_05. Windows: Reproducible with 8.0.0-b132, but not 2.2.45-b18.

      Description

      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();
          }
      }

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported: