-1
J'essaie d'ajouter des itmes dans mon checkComboBox mais je ne sais pas pourquoi je ne le fais pas. Voici ce que je suis en train de faire ceci:Javafx: Comment ajouter des itmes dans checkcombobox?
`// initialinzing FXML in my controller`
@FXML
CheckComboBox<String> checkComboBox;
// create the data to show in the CheckComboBox
final ObservableList<String> strings = FXCollections.observableArrayList();
for (int i = 0; i <= 10; i++) {
strings.add("Item " + i);
}
// Create the CheckComboBox with the data
checkComboBox = new CheckComboBox<String>(strings);
// and listen to the relevant events (e.g. when the selected indices or
// selected items change).
checkComboBox.getCheckModel().getSelectedItems().addListener(new ListChangeListener<String>() {
public void onChanged(ListChangeListener.Change<? extends String> c) {
System.out.println(checkComboBox.getCheckModel().getSelectedItems());
}
});
}
Il est fait. juste fait un petit changement tout en ajoutant ma liste observable dans mon checkcombobox. checkComboBox.getItems(). AddAll (chaînes); istead de checkComboBox = new CheckComboBox (chaînes de caractères); –
Pourquoi créez-vous un nouveau 'CheckComboBox'? L'ajoutez-vous à la scène n'importe où? –
Oui! J'ai ajouté 'checkComboBox' dans ma scène. C'est là que je me trompais en créant un nouveau 'checkComboBox'. Au lieu de faire un nouveau checkComboBox je dois appeler directement la fonction 'getItems(). AddAll (strings)' pour ajouter mon ObservableList dans mon checkComboBox –