Making a table editable

To allow editing of the cell contents, we need to provide two more things, CellFactory and onEditCommit logic:

// chapter10/table/EditableTableViewDemo.java// TextField based editable cellcolumnTitle.setCellFactory(TextFieldTableCell.forTableColumn());// logic which happes once editing is finishedcolumnTitle.setOnEditCommit((CellEditEvent<Chapter, String> t) -> {    // setting new value for the title    t.getRowValue().setTitle(t.getNewValue());});table.setEditable(true);

Now, you can double-click on the title cell, enter the new title, and it will be instantly applied to the data model:

Get Mastering JavaFX 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.