Editing JavaFX TableView Integer Cell

In the official documentation JavaFX editing data in a table is an example only String, in my program, I have two columns INTEGER, to edit them, that I use: select a row, click the button, a new form, after its user filled in, click ok, then the data will be changed. Now I want to move from this to direct input to the table. How to do this using 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

+4
source share
1 answer

You can do

 dataColumn.setCellFactory( TextFieldTreeTableCell.forTreeTableColumn(new IntegerStringConverter())); 
+7
source

All Articles