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

ListView: EditEvent on cancel has incorrect index

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 8, 9, 10
    • Fix Version/s: tbd
    • Component/s: javafx
    • Environment:

      java9-ea-u180

      Description

      To reproduce, run the example, start editing anywhere and cancel by esc:
      - expected: the index of the EditEvent received in onEditCancel must be the same as the index received in onEditStarted
      - actual: the index in cancel is always -1

      The example:

      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.scene.Scene;
      import javafx.scene.control.ListView;
      import javafx.scene.control.cell.TextFieldListCell;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      /**
       * ListView: EditEvent on cancel has incorrect index
       */
      public class ListViewEditCancelIndexBug extends Application {

          private int editIndex;

          @Override
          public void start(Stage primaryStage) {
              ListView<String> simpleList = new ListView<>(FXCollections
                      .observableArrayList("Item1", "Item2", "Item3", "Item4"));
              simpleList.setEditable(true);
              simpleList.setCellFactory(TextFieldListCell.forListView());

              simpleList.setOnEditStart(t -> editIndex = t.getIndex());

              simpleList.setOnEditCancel(t -> {

                  if (editIndex != t.getIndex())
                      System.out.println("expected index: " + editIndex + " actual: "
                              + t.getIndex());
              });

              BorderPane root = new BorderPane(simpleList);
              Scene scene = new Scene(root, 300, 250);

              primaryStage.setTitle("Hello World!");
              primaryStage.setScene(scene);
              primaryStage.show();
          }

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              aghaisas Ajit Ghaisas
              Reporter:
              fastegal Jeanette Winzenburg
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: