为什么我的 JavaFX Tableview 不可编辑?

Why is my JavaFX Tableview not editable?

为什么我的 TableView 不允许编辑 ID 列? getPenaltyIdProperty() returns IntegerProperty(准确地说是 SimpleIntegerProperty),但我认为这将允许编辑通过绑定自动发生。我错过了什么?

public class PenaltyDashboardManager { 

    private final TableView<Penalty> penaltyTable = new TableView<Penalty>();

/* ... */

    private void initializeTable() { 

        penaltyTable.setItems(Penalty.getPenaltyManager().getPenalties());
        penaltyTable.setEditable(true);

        TableColumn<Penalty,Number> penaltyId = new TableColumn<>("ID");
        penaltyId.setCellValueFactory(c -> c.getValue().getPenaltyIdProperty());
        penaltyId.setEditable(true);

        /* ... */

        penaltyTable.getColumns.add(penaltyId);
    }

}

您需要一个细胞工厂来生产允许用户编辑值的细胞。例如

penaltyId.setCellFactory(TextFieldTableCell.forTableColumn(new NumberStringConverter());