哪个ChoiceBox-Event可供选择?

Gun*_*don 5 java javafx javafx-2 fxml

我使用JavaFX Scene Builder将一个ChoiceBox放在一个fxml中.

FXML有一个分配给它的控制器.

我的问题是:如果我想了解更改的值,我需要注册哪个事件?

onInputMethodTextChanged="#languageSelectionModified"
Run Code Online (Sandbox Code Playgroud)

这不适用于以下代码

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

这仅适用于初始点击(即打开列表,而不是选择项目时):

onMouseClicked="#languageSelectionModified"
Run Code Online (Sandbox Code Playgroud)

虽然鼠标事件永远不会是一个很好的选择,因为触摸或键盘是输入法的情况,它仍然证明可以到达System.out.

我绝对不知道这些东西在哪里被记录(在默认的Java-API中它们不是)

jew*_*sea 5

在控制器中的@FXML注入的选择框中添加一个侦听器:

choicebox.getSelectionModel().selectedItemProperty().addListener(choiceboxSelectionChangeListener);
Run Code Online (Sandbox Code Playgroud)

您还可以绑定到所选项目:

label.textProperty().bind(choicebox.getSelectionModel().selectedItemProperty());
Run Code Online (Sandbox Code Playgroud)

这是在FXML中定义的ComboBox的控制器中连接侦听器的示例。ChoiceBox的逻辑几乎相同。