tmn
tmn

Reputation: 11559

Why is my JavaFX Tableview not editable?

Why is my TableView not allowing the ID column to be editable? The getPenaltyIdProperty() returns an IntegerProperty (a SimpleIntegerProperty to be exact) and yet I thought this would allow the edits to happen automatically via bindings. what am I missing?

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);
    }

}

Upvotes: 1

Views: 774

Answers (1)

James_D
James_D

Reputation: 209684

You need a cell factory to produce a cell that allows the user to edit the value. E.g.

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

Upvotes: 3

Related Questions