我有一个 tableview,我想要做的是基于一个具有环境类型的单选按钮;QA、DEV、PROD 等。它会向表格视图添加一个可观察列表,如果您单击不同的单选按钮,它会清除先前环境的列表并在表格视图中显示关联的可观察列表。
我的问题是,由于 obs 列表是通过引用传递到 tableview 中的,因此 tableview.getItems().clear() 会清除 tableview 和列表。我试图做到这一点 - 它只清除表格视图中显示的内容,而不是原始列表。
ObservableList<BarFile> devCheckboxList = FXCollections.observableArrayList();
//List gets populated with files elsewhere
switch (chk.getText()) {
//Check to see which checkbox is selected
case "DEV":
tableView.getItems().clear();
System.err.println("DEV IS TRUE");
environmentCheck("DEV");
//Add to listview
tableView.setItems(devCheckboxList);
break;
}
如果您不想清除现有列表,请不要调用clear()
:
ObservableList<BarFile> devCheckboxList = FXCollections.observableArrayList();
//List gets populated with files elsewhere
switch (chk.getText()) {
//Check to see which checkbox is selected
case "DEV":
// tableView.getItems().clear();
System.err.println("DEV IS TRUE");
environmentCheck("DEV");
//Add to listview
tableView.setItems(devCheckboxList);
break;
}
由于您无论如何都要替换表格的整个列表,因此调用对clear()
表格中显示的内容没有影响。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句