Reputation: 11
I have an FXML file which have a combo box which i want to populate in initialize() method in controller
Controller class:
@FXML
private ComboBox<String> comboBox;
void initialize()
{
comboBox.addItem("123");
}
Whenever i want to complie i've got an error:
"The method addItem(String) is undefined for the type ComboBox<String>"
After reading lecture from oracle i've got the information, that combo box works for Objects, which String is, isnt it ?
What can be wrong?
Upvotes: 0
Views: 585
Reputation: 15146
You need to use setItems(ObservableList<T>)
.
addItem
isn't a method declared for ComboBox
. Check out the docs.
You can add items by creating an observable list, then passing it to setItems
:
comboBox.setItems(FXCollections.observableArrayList("123"))
Or you can pass the ComboBox
the list of items via it's constructor.
Upvotes: 1