I have a simple JavaFX GUI where I have an HBox across the top that contains several ComboBoxes that will eventually act as filters. I can't figure out how to reset the value of the ComboBoxes to an empty string when clicking a "clear" button. Any tips would be appreciated.
Update: Here's my code that works for me
// private EventHandler to pass to the clearButton's action
EventHandler<ActionEvent> clearAction = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
List<Node> nodes = topPane.getChildren();
for (Node node : nodes) {
if (node instanceof ComboBox) {
((ComboBox) node).getSelectionModel().clearSelection();
}
}
}
};
clearButton.setOnAction(clearAction);