Shersha Fn
Shersha Fn

Reputation: 1571

How to set default value in comboBox javafx?

I need to set a default value for a ComboBox from an ObservableArrayList, I am trying to set the first value in my ArrayList as a default value.

List = FXCollections.observableArrayList(arrayList);
comboBox.setItems(List);

Upvotes: 26

Views: 66310

Answers (3)

Alen
Alen

Reputation: 11

comboBox.getSelectionModel().clearSelection();

I was just looking for a way to leave it in the same way I had started with, in my case with an introductory text

Upvotes: 1

simpleuser
simpleuser

Reputation: 1682

comboBox.getSelectionModel().select(index);

where index is the integer position of the item to select in the selection model, or a value from and of the same type as the arrayList.

Upvotes: 25

Uluk Biy
Uluk Biy

Reputation: 49185

comboBox.getSelectionModel().selectFirst();

Upvotes: 68

Related Questions