如何从表列javafx中删除行

Pim*_*Pim 3 java javafx tablecolumn

在此输入图像描述

这些是我的表格栏目 课程说明.如果单击一行(该行变为"活动"/突出显示),并按下" 删除"按钮,则应该删除该行,我该怎么做?

我的课程列的代码:(以及我添加到删除按钮的事件监听器?)

@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(.....
Run Code Online (Sandbox Code Playgroud)

Jam*_*s_D 16

只需从表格视图的项目列表中删除所选项目即可.如果你有

TableView<MyDataType> table = new TableView<>();
Run Code Online (Sandbox Code Playgroud)

然后你做

deleteButton.setOnAction(e -> {
    MyDataType selectedItem = table.getSelectionModel().getSelectedItem();
    table.getItems().remove(selectedItem);
});
Run Code Online (Sandbox Code Playgroud)