从组中选择单选按钮时会触发什么样的JavaFX2事件?如何处理它?</ p>
答案 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());
}
}