I’m working on a JavaFX app, and I need some help with filtering nodes in an AnchorPane using both a ComboBox and a TextBox. Basically, I want users to be able to select a category from the ComboBox (like “All”, “Labels”, “Buttons”, etc.) and type a keyword into the TextBox. Then, I want to show only the nodes that match the selected category and keyword.
ObjectProperty<Predicate<Node>> categoryFilter = new SimpleObjectProperty<>();
ObjectProperty<Predicate<Node>> keywordFilter = new SimpleObjectProperty<>();
FilteredList<Node> filteredItems = new FilteredList<>(FXCollections.observableArrayList(anchorPane_stackedView.getChildren()));
filteredItems = new FilteredList<>(anchorPane_stackedView.getChildren());
Bindings.bindContent(anchorPane_stackedView.getChildren(), filteredItems);
categoryFilter.bind(Bindings.createObjectBinding(() -> node -> {
// criteria
}, combo_selectedFilter.selectedItemProperty()));
keywordFilter.bind(Bindings.createObjectBinding(() -> node -> {
// criteria
}, textBox_filter.textProperty()));
filteredItems.predicateProperty().bind(Bindings.createObjectBinding(
() -> keywordFilter.get()
.and(categoryFilter.get()),
keywordFilter,
categoryFilter
));