What ChoiceBox-Event Choice to Choose?

I placed ChoiceBox inside fxml using Java Scene Builder.

FXML has a controller assigned to it.

My question is: what event do I need to register if I want to know about the 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 a list, not when selecting an item):

onMouseClicked="#languageSelectionModified"

Although Mouse-Events will never be a good choice due to situations where a sensor or keyboard is an input method, it still proves that System.out can be achieved.

I absolutely do not know where these things are documented (in the Java API, this is not the case by default)

+5
source share
2 answers

Add a listener to your @FXML select block in your controller:

choicebox.getSelectionModel().selectedItemProperty().addListener(choiceboxSelectionChangeListener);

:

label.textProperty().bind(choicebox.getSelectionModel().selectedItemProperty());

ComboBox, FXML. ChoiceBox .

+4

onAction:

<ChoiceBox onAction="#languageSelectionModified" />
0

All Articles