Reputation: 89
I have tried everything to figure out why my combobox will not get populated but nothing works.
In my FXML file I have.
<ComboBox fx:id="comboBox" layoutX="162.0" layoutY="15.0" prefHeight="25.0" prefWidth="334.0" promptText="Select past popular pizza" />
In my controller I have the following
public class ServeController {
public ObservableList<String> pizzas1 = FXCollections.observableArrayList();
@FXML public ComboBox<String> comboBox;
private void initialize() {
comboBox.getItems().addAll(
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]"
);
}
I have even tried with
public ObservableList<String> pizzas1 = FXCollections.observableArrayList("1","2","3","4");
to try to get some kind of data to show up but nothing seems to be working.
Upvotes: 1
Views: 85
Reputation: 18792
I assume that if you add a printout to initialize()
you'll see that it is not invoked.
To get initialize()
invoked you need to annotate it: @FXML private void initialize()
Upvotes: 2
Reputation: 2210
I assume that you are initalizing controller in "standard" way. I'm guesing that private void initialize()
method is never invoked. Your ServeController
does not implement Initializable
interface. Correct code should look as following:
public class ServeController implements Initializable {
public ObservableList<String> pizzas1 = FXCollections.observableArrayList();
@FXML
public ComboBox<String> comboBox;
@Override
public void initialize(URL url, ResourceBundle rb) {
comboBox.getItems().addAll(
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]"
);
}
}
Upvotes: 2