Javafx:如何在 checkcombobox 中添加项目?

Javafx: How to add itmes in checkcombobox?

我正在尝试在我的 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());
         }
     });
     }

这段代码工作正常

我的fxml代码

<CheckComboBox fx:id="addFeaturesCheckComboBox" prefHeight="25.0" prefWidth="192.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />

我的控制器代码:

//to initialize my checkComboBox
@FXML
CheckComboBox<String> addFeaturesCheckComboBox;

public void initialize() throws SQLException{

ObservableList<String> strings = FXCollections.observableArrayList();
     for (int i = 0; i <= 10; i++) {
         strings.add("Item " + i);
     }
addFeaturesCheckComboBox.getItems().addAll(strings);
//listen to the relevant events (e.g. when the selected indices or
     // selected items change).

     addFeaturesCheckComboBox.getCheckModel().getSelectedItems().addListener(new ListChangeListener<String>() {
         public void onChanged(ListChangeListener.Change<? extends String> c) {

             selectedFeatures = addFeaturesCheckComboBox.getCheckModel().getSelectedItems();
         }
     });
 }