Reputation: 4034
When I create a JavaFX 2.0 ChoiceBox instance like this:
final ChoiceBox<String> fontChBox =
new ChoiceBox<>(FXCollections.observableArrayList("First", "Second", "Third"));
a choice box is displayed with no selection. I would like to select the first element by default. How to do it in JavaFX 2.0?
Upvotes: 22
Views: 32356
Reputation: 21
Try following solution
//use this to display first option.
mychoicebox.getSelectionModel().selectFirst();
//to display specific option
mychoicebox.getSelectionModel().selectFirst(index position);
Upvotes: 2
Reputation: 451
Try this,
fontChBox.getSelectionModel().select(0);
if you need to select an element other than the first, pass the index of the element instead of zero.
Upvotes: 2
Reputation: 25950
Give a try to this statement:
fontChBox.getSelectionModel().selectFirst();
Upvotes: 49