0

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;
    });
  • 1
    Use `Bindings.convert`. See an example here: https://stackoverflow.com/questions/34546433/javafx-binding-a-textproperty-eg-label-to-a-simple-integer/34546915#34546915 – Itai Aug 15 '18 at 11:20
  • 1
    Please provide a [mcve] that demonstrates the problem. – kleopatra Aug 15 '18 at 12:08
  • I would personally steer clear of using the keyword `Task` in any project. What's `cell.itemProperty`? Is this a way around `updateItem`? – SedJ601 Aug 15 '18 at 13:42

0 Answers0