Which ChoiceBox-Event to choose?

Viewed 9626

I placed a ChoiceBox inside an fxml with JavaFX Scene Builder.

The FXML has a controller assigned to it.

My question is: Which event do I need to register if I want to know about changed values?

onInputMethodTextChanged="#languageSelectionModified"

this does not work with the following code

public void languageSelectionModified(Event event) {
    ChoiceBox<String> box = (ChoiceBox<String>) event.getSource();
    System.out.println(box.getValue());
}

and this only works for the initial click (i.e. opening the list, not when selecting an item):

onMouseClicked="#languageSelectionModified"

Although the Mouse-Events would never be a good choise because of situations where the touch or keyboard is the input-method, it still proves that the System.out can be reached.

I have absolutly no idea where those things are documentated (in the default Java-API they are not)

2 Answers

You can also use FXML onAction attribute:

<ChoiceBox onAction="#languageSelectionModified" />
Related