usertest
usertest

Reputation: 2252

JavaFX TableView edit integer cell

In the official documentation of JavaFX on edit data a table view, there is example only for String, in my program I have two INTEGER columns, to edit them I use : select the row, click button, new form shows up, after the user fill it, hit ok, then data changes. Now I want to move from this to direct input in the table. How can I do this with Integer Columns.

    TreeTableColumn<RootMaster, Integer> dataColumn = new TreeTableColumn<>(rs.getString("tab.budget.table.column.budgeted"));
    dataColumn.setEditable(true);
    dataColumn.setCellValueFactory(new TreeItemPropertyValueFactory<RootMaster, Integer>("budgetSum"));
    dataColumn.setCellFactory(col -> {
        TreeTableCell<RootMaster, Integer> cell = new TreeTableCell<RootMaster, Integer>() {
            @Override
            public void updateItem(Integer item, boolean empty) {
                super.updateItem(item, empty);
                if (empty) {
                    setText(null);
                } else {
                    setText(item.toString());
                }
            }
        };
        cell.setAlignment(Pos.CENTER);
        return cell;
    });

Thanks

Upvotes: 5

Views: 6255

Answers (1)

James_D
James_D

Reputation: 209225

You can do

dataColumn.setCellFactory(
    TextFieldTreeTableCell.forTreeTableColumn(new IntegerStringConverter()));

Upvotes: 9

Related Questions