I have a table, and I create the columns in the following way:
@FXML
TableView<Row> tableView = new TableView<>();
private void createColumns(int numberOfColumns, Row firstRow, boolean errorsDisplayed) {
for (int i = 0; i < numberOfColumns; i++) {
int colNum = i;
TableColumn<Row, String> column = new TableColumn<>(firstRow.getCell(i).toString());
column.setCellValueFactory(param -> {
int index = param.getTableView().getColumns().indexOf(param.getTableColumn());
return new SimpleStringProperty(param.getValue().getLastCellNum() > index
? param.getValue().getCell(index).toString() : null);
});
if (!errorsDisplayed || (colNum != numberOfColumns - 1 && colNum != numberOfColumns - 2)) {
column.setCellFactory(TextFieldTableCell.forTableColumn());
column.setOnEditCommit(param -> param.getTableView().getItems().get(param.getTablePosition()
.getRow()).getCell(colNum).setCellValue(param.getNewValue()));
}
tableView.getColumns().add(column);
}
}
Is there a way I could store different states of the table in order to restore them when the undo button being pressed?
I create an app that can hopefully help. It is probably full of traps and pitfalls so don't attempt to use the code as it. I got the Undo/Redo ideas from here. Two
Stackare used to implement the ideas. I got the code for theTableViewfrom here. Changes are committed on focus lost.Main
Person
MyAction
UndoRedo
**GenerateUniqueId