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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: openjfx19
    • Component/s: javafx
    • Environment:

      java9-ea-u180

      Backports

        Description

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

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  Created:
                  Updated:
                  Resolved: