Issue
These are my table columns Course and Description. If one clicks on a row (the row becomes 'active'/highlighted), and they press the Delete button it should remove that row, how do I do this?
The code for my Course column: (and what event listener do I add to my delete button?)
@SuppressWarnings("rawtypes")
TableColumn courseCol = new TableColumn("Course");
courseCol.setMinWidth(300);
courseCol.setCellValueFactory(new PropertyValueFactory<Courses, String>("firstName"));
final Button deleteButton = new Button("Delete");
deleteButton.setOnAction(.....
Solution
Just remove the selected item from the table view's items list. If you have
TableView<MyDataType> table = new TableView<>();
then you do
deleteButton.setOnAction(e -> {
MyDataType selectedItem = table.getSelectionModel().getSelectedItem();
table.getItems().remove(selectedItem);
});
Answered By - James_D