How can I remove the selected row from the TableView? (JavaFX with FXML)
So I am trying to delete the highlighted row in the TableView in my program.
I have looked through a lot of tutorials online, but I really can't think of it. I followed the example of CodeMakery which is in Eclipse, but I cannot get it to work with IntelliJ (due to some obvious JDK issues?)
This is the code from CodeMakery:
private void handleDeletePerson() {
int selectedIndex = personTable.getSelectionModel().getSelectedIndex();
if (selectedIndex >= 0) {
personTable.getItems().remove(selectedIndex);
} else {
// Nothing selected.
Alert alert = new Alert(AlertType.WARNING);
alert.initOwner(mainApp.getPrimaryStage());
alert.setTitle("No Selection");
alert.setHeaderText("No Person Selected");
alert.setContentText("Please select a person in the table.");
alert.showAndWait();
}
}
Could you please help me understand how to delete the selected row?
+3
source to share