如何从表列javafx中删除行 [英] How to delete row from table column javafx

查看:202
本文介绍了如何从表列javafx中删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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(.....


推荐答案

只需从表格视图的项目列表中删除所选项目。如果您有

Just remove the selected item from the table view's items list. If you have

TableView<MyDataType> table = new TableView<>();

然后你做

deleteButton.setOnAction(e -> {
    MyDataType selectedItem = table.getSelectionModel().getSelectedItem();
    table.getItems().remove(selectedItem);
});

这篇关于如何从表列javafx中删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆