答案 0 :(得分:1)
final ToggleGroup group = new ToggleGroup();
RadioButton rb1 = new RadioButton("Rb1");
rb1.setToggleGroup(group);
RadioButton rb2 = new RadioButton("Rb2");
rb2.setToggleGroup(group);
group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
public void changed(ObservableValue<? extends Toggle> ov,
Toggle old_toggle, Toggle new_toggle) {
if (group.getSelectedToggle() == rb1) {
nameLabel.setText("M Name");
// The rest of your logic
}
else if(group.getSelectedToggle() == rb2) {
nameLabel.setText("F Name");
}
}
});