JavaFX RadioButton事件处理

时间:2013-10-23 07:36:12

标签: event-handling radio-button javafx-2

从组中选择单选按钮时会触发什么样的JavaFX2事件?如何处理它?<​​/ p>

1 个答案:

答案 0 :(得分:6)

鉴于zodiacSigns是一个单选按钮所属的组,

zodiacSigns.selectedToggleProperty().addListener(new OnToggleHandler());

将事件处理程序OnToggleHandler发送到按钮组(在JavaFX中称为切换组)。以下是OnToggleHandler

的代码
private class OnToggleHandler implements ChangeListener<Toggle> {

    @Override
    public void changed(ObservableValue<? extends Toggle> ov, Toggle t, Toggle t1) {
        dailyHoro.editReading(((RadioButton) t1).getText());
        dailyHoro.print();
        System.out.println("Old: " + ((RadioButton) t).getText() + ", New: " + ((RadioButton) t1).getText());
        if (dailyHoro.getText() == null)
            textEditor.setText("");
        else
            textEditor.setText(dailyHoro.getText());
    }
}