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

[ListView] getSelectedItems() returns null element.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 8u112
    • Fix Version/s: None
    • Component/s: javafx
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      Run this SSCCE:

      "

      import javafx.application.Application;
      import static javafx.application.Application.launch;
      import javafx.beans.InvalidationListener;
      import javafx.beans.Observable;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.ListView;
      import javafx.scene.control.SelectionMode;
      import javafx.stage.Stage;

      public class ListViewTest extends Application {

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

          ObservableList<String> list = FXCollections.observableArrayList("Kevin Rushforth", "Jonathan Giles");

          @Override
          public void start(Stage primaryStage) throws Exception {

              ListView listView1 = new ListView(list);
              listView1.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

              for (String string : list) {
                  listView1.getSelectionModel().select(string);
              }
              primaryStage.setScene(new Scene(listView1));
              primaryStage.setWidth(800);
              primaryStage.setHeight(600);
              primaryStage.show();

              listView1.getSelectionModel().getSelectedItems().addListener(new InvalidationListener() {
                  @Override
                  public void invalidated(Observable observable) {
                      System.out.println(listView1.getSelectionModel().getSelectedItems());
                      System.out.println(listView1.getSelectionModel().getSelectedIndex());
                      System.out.println(listView1.getSelectionModel().getSelectedItem());
                      System.out.println(listView1.getSelectionModel().getSelectedIndices());
                  }
              });
          }
      }

      "

      Simply click on the second item "Jonathan Giles", then you see in the console:
      "[null]
      1
      Jonathan Giles
      [1]"

      As you can see, the selection model has a null element in the getSelectedItems() list.

      Tested with 8u112 Build b01

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jgiles Jonathan Giles
              Reporter:
              shadzic Samir Hadzic
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: