gpt4 book ai didi

JavaFX:如何在TableView中选择和删除多个对象

转载 作者:行者123 更新时间:2023-12-02 04:27:30 25 4
gpt4 key购买 nike

如何在 TableView 中选择和删除多个对象?

public class Controller implements Initializable{
public TableView<Student> fxClassroom;
public void deleteStudent(){
ObservableList<Student> studentSelected, allStudents;
allStudents = fxClassroom.getItems();
studentSelected = fxClassroom.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
studentSelected.forEach(allStudents::remove);
}
}

但在 Eclipse 中,我不断收到此错误:

Type mismatch cannot convert void to ObservableList

最佳答案

试试这个:

 public class Controller implements Initializable{
public TableView<Student> fxClassroom;
@Override
public void initialize(URL url, ResourceBundle rb) {
....
fxClassroom.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
....
}

public void deleteStudent(){
ObservableList<Student> studentSelected, allStudents;
allStudents = fxClassroom.getItems();
studentSelected = fxClassroom.getSelectionModel().getSelectedItems();
allStudents.removeAll(studentSelected);


}
}

关于JavaFX:如何在TableView中选择和删除多个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31948466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com