apr*_*l21 5 javafx tableview fxml
所以,我试图在我的程序中删除 TableView 中突出显示的行。
我在网上看了很多教程,但真的无法理解这一点。我遵循了 Eclipse 中的 CodeMakery 的示例,但我无法让它在 IntelliJ 上工作(因为一些明显的 JDK 问题?)
这是来自 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();
}
}
Run Code Online (Sandbox Code Playgroud)
你能帮我理解如何使选定的行被删除吗?