Sebastian explained quite well, although only if you are only interested in the actual value selected in the selection field and donβt really care about the index, you can simply use selectedItemProperty instead of selectedIndexProperty.
Also ChangeListener is a functional interface, you can use lambda here when you go with java 8. I just changed Sebastian's example a little. NewValue is the new value selected.
ChoiceBox<String> box = new ChoiceBox<String>(); box.getItems().add("1"); box.getItems().add("2"); box.getItems().add("3"); box.getSelectionModel() .selectedItemProperty() .addListener( (ObservableValue<? extends String> observable, String oldValue, String newValue) -> System.out.println(newValue) );
Steve park
source share