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 cell
columnTitle.setCellFactory(TextFieldTableCell.forTableColumn());
// logic which happes once editing is finished
columnTitle.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:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.75.221