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

[ListView, TreeView, TableView, TreeTableView] selectionModel selectedItem returns wrong item.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8
    • 7u13
    • javafx
    • None

    Description

      Please run the code.
      Select the first item.
      Click the Remove button, which removes the first item.
      Click the Show button, which says, that the selected item is "String1", although it is no longer in the list and cannot be the selected item. (The real selected item is in fact "String2")

      This only works, if you removed the first item in the list.

      This bug might be related to RT-27820 !?



      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ListView;
      import javafx.scene.layout.VBoxBuilder;
      import javafx.stage.Stage;

      public class TestApp2 extends Application {
          public static void main(String[] args) {
              Application.launch();
          }

          private ObservableList<String> items = FXCollections.observableArrayList("String1", "String2", "String3", "String4");

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

              final ListView<String> listView = new ListView<String>();
              listView.setItems(items);

              Button button = new Button("Remove");
              button.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      items.remove(listView.getSelectionModel().getSelectedItem());
                  }
              });

              Button btnShow = new Button("Show");
              btnShow.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      System.out.println(listView.getSelectionModel().getSelectedItem());
                  }
              });

              Scene scene = new Scene(VBoxBuilder.create().children(listView, button, btnShow).build());
              stage.setScene(scene);
              stage.show();
          }
      }

      Attachments

        Issue Links

          Activity

            People

              jgiles Jonathan Giles
              cschudtjfx Christian Schudt (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported: