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);
}
}
- 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);
}
}
- blocks
-
JDK-8266969 All Cells: cancelEvent must return correct editing location
- Closed
- duplicates
-
JDK-8165214 ListView.EditEvent.getIndex() does not return the correct index
- Resolved
- relates to
-
JDK-8165214 ListView.EditEvent.getIndex() does not return the correct index
- Resolved
-
JDK-8187229 Tree/TableCell: cancel event must return correct editing location
- Resolved