Reputation: 6188
What kind of JavaFX2 event is fired when selecting a radio button from a group and how can I handle it?
Upvotes: 3
Views: 5253
Reputation: 6188
Given zodiacSigns
is a group which radio buttons belong to,
zodiacSigns.selectedToggleProperty().addListener(new OnToggleHandler());
will the event handler OnToggleHandler
to the button group (called toggle group in JavaFX). Below is the code for 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());
}
}
Upvotes: 6