Register a listener with the country combo box and update the state combo box when the selected item changes:
cbxCountry.valueProperty().addListener((obs, oldValue, newValue) -> {
if (newValue == null) {
cbxState.getItems().clear();
cbxState.setDisable(true);
} else {
// sample code, adapt as needed:
List<State> states = stateDAO.getStatesForCountry(newValue);
cbxState.getItems().setAll(states);
cbxState.setDisable(false);
}
});
You could also do this with bindings if you prefer:
cbxState.itemsProperty().bind(Bindings.createObjectBinding(() -> {
Country country = cbxCountry.getValue();
if (country == null) {
return FXCollections.observableArrayList();
} else {
List<State> states = stateDAO.getStatesForCountry(country);
return FXCollections.observableArrayList(states);
}
},
cbxCountry.valueProperty());
(and if you want the disable functionality from the solution above also do cbxState.disableProperty().bind(cbxCountry.valueProperty().isNull());
).