Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8280380 | tbd | Jeanette Winzenburg | P3 | Closed | Not an Issue |
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);
}
}
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);
}
}
- backported by
-
JDK-8280380 ListView, TableView, TreeView: receives editCancel event when edit is committed
- Closed
- relates to
-
JDK-8094887 [TextFieldTableCell] (and others) to cancel or commit edit on focus lost causes new cell to be edited
- Resolved
-
JDK-8124615 TreeView gets onEditCancel event when changes are commited
- Closed