Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX TableView edit integer cell

Tags:

java

javafx

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

like image 653
usertest Avatar asked Aug 10 '15 11:08

usertest


1 Answers

You can do

dataColumn.setCellFactory(
    TextFieldTreeTableCell.forTreeTableColumn(new IntegerStringConverter()));
like image 105
James_D Avatar answered Sep 29 '22 05:09

James_D