【发布时间】:2019-10-07 17:01:11
【问题描述】:
我目前正在尝试使用通过场景生成器创建的多个选择框来过滤我的 FXML 列表视图。
好吧,在第一次我尝试使用文本字段而不是使用选择框将过滤器功能实现到我的工作中,只是为了测试它是否适用于我的自定义列表视图并且它有效。
但现在我无法弄清楚如何使用多个选择框而不是仅使用文本字段来实现它。
希望这里的人能给我一些关于如何做到这一点的见解,谢谢。
这些是我的选择框
@FXML
private ChoiceBox choiceBox1;
@FXML
private ChoiceBox choiceBox2;
@FXML
private ChoiceBox choiceBox3;
@FXML
private ChoiceBox choiceBox4;
这是我实现过滤器的地方
@Override
public void initialize(URL location, ResourceBundle resources) {
filterField.textProperty().addListener((observable, oldValue, newValue) -> {
filteredData.setPredicate(student -> {
if (newValue == null || newValue.isEmpty()) {
return true;
}
String lowerCaseFilter = newValue.toLowerCase();
if (student.getName().toLowerCase().contains(lowerCaseFilter)) {
return true;
} else if (student.getStatus().toLowerCase().contains(lowerCaseFilter)) {
return true;
}
return false;
});
});
listView.setItems(filteredData);
listView.setCellFactory(studentListView -> new StudentListViewCell());
}
【问题讨论】:
标签: java listview javafx filter fxml