我将 JFoenix 库用于我的 Comboboxes。
' boxLeague.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> boxTeams.setItems(listPremierLeague)); ' 当从boxLeague Combobox中选择任何内容时,会将所有文本放入boxTeams Combobox,但我想要做的是当在boxLeague中选择特定项目时,然后填充另一个组合框。
public class Controller implements Initializable {
@FXML
private JFXComboBox<String> boxLeague;
@FXML
private JFXComboBox<String> boxTeams;
@FXML
private JFXComboBox<String> boxPlayers;
ObservableList<String> listLeagues = FXCollections.observableArrayList(
"Bundesliga", "La Liga", "Ligue 1", "Premier League", "Serie A", "Champions League", "Europa League");
ObservableList<String> listPremierLeague = FXCollections.observableArrayList(
"Arsenal", "Bournemouth", "Brighton", "Burnley", "Chelsea", "Crystal Palace", "Everton");
@Override
public void initialize(URL location, ResourceBundle resources) {
boxLeague.setItems(listLeagues);
boxLeague.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> boxTeams.setItems(listPremierLeague));
}
}