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

ListView, TableView, TreeView: receives editCancel event when edit is committed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • jfx19
    • 9
    • javafx
    • java9-ea-u180

        To reproduce, run the example, edit any item, press enter to commit, see the output

        EDIT_START on 1
        EDIT_COMMIT on 1
        EDIT_CANCEL on -1 // this is unexpected

        The underlying reason is that the default commitHandler (like any reasonable implementation would do) replaces the old value with the edited value in the list's items - skin listens and cancels the edit.

        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: receives both editCommit (expected) and
         * editCancel (unexpected) when edit committed
         */
        public class ListViewEditCancelOnCommitBug extends Application {

            @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.addEventHandler(ListView.editStartEvent(), t ->
                    System.out.println(t.getEventType() + " on " + t.getIndex()));
                simpleList.addEventHandler(ListView.editCommitEvent(), t ->
                    System.out.println(t.getEventType() + " on " + t.getIndex()));
                simpleList.addEventHandler(ListView.editCancelEvent(), t ->
                    System.out.println(t.getEventType() + " on " + t.getIndex()));
         
                BorderPane root = new BorderPane(simpleList);
                Scene scene = new Scene(root, 300, 250);

                primaryStage.setScene(scene);
                primaryStage.show();
            }

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

              fastegal Jeanette Winzenburg
              fastegal Jeanette Winzenburg
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: