Have built a simple todo list application with JavaFX
As I add tasks, they will be listed in a ListView, the user should be able to delete the task by right-clicking them and selecting "delete task" - have achieved this by handling the event over cell using the context menu and setOnAction method inside a cell factory.
Since I've used a cell factory explicitly, I understand the default bindings of underlying data and formatting does not hold good. so I tried to bind them manually after reading this article . but I get this error. error message
vTaskList.setCellFactory(param -> {
ListCell<Task> cell = new ListCell<>();
// setting context menu for cell
ContextMenu menu = new ContextMenu();
cell.textProperty().bind(cell.itemProperty());
MenuItem deleteTask = new MenuItem();
deleteTask.setOnAction(del -> {
vTaskList.getItems().remove(vTaskList.getSelectionModel().getSelectedIndex());
});
deleteTask.setText("Delete Task");
menu.getItems().add(deleteTask);
cell.setContextMenu(menu);
return cell;
});