5

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

1 Answer 1

9

You can do

dataColumn.setCellFactory(
    TextFieldTreeTableCell.forTreeTableColumn(new IntegerStringConverter()));
Sign up to request clarification or add additional context in comments.

3 Comments

Not sure why you are getting that error; it works fine for me. Are you sure you declared it as a TreeTableColumn and not a TableColumn? You have all the correct imports (javafx.scene.control.cell.TextFieldTreeTableCell and javafx.util.converter.IntegerStringConverter)?
TextFieldTableCell should e use
@ChandanaSrilal I'm not sure I understand the comment, but you can only use a TextFieldTableCell in a TableColumn, not in a TreeTableColumn (this question is about a TreeTableView).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.