如何从 ToggleGroup 获取选定的单选按钮 [英] How to get selected radio button from ToggleGroup

查看:41
本文介绍了如何从 ToggleGroup 获取选定的单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 JavaFX 8 和 SceneBuilder.我在 FXML 文件中创建了一些单选按钮,并为其中的单选按钮列表指定了一个 toggleGroup 名称.所以,现在我想在我的控制器中获得 toggleGroup 的选定单选按钮,我是否需要再次将所有单选按钮作为控制器中的字段,或者只是 toggleGroup 对象将为我获取选定的单选按钮(仅该单选按钮的文本,而不是按钮对象).

I an working on JavaFX 8 and SceneBuilder. I created some radio buttons in the FXML File and specified a toggleGroup name to a radio button list in that. So, now I want to get the toggleGroup's selected radio button in my controller, do I need to make all the radio buttons again as fields in the controller, or just the toggleGroup object will get me the selected radio button (the text of that radio button only, not the button object).

推荐答案

 @FXML
 ToggleGroup right; //I called it right in SceneBuilder.

稍后在方法中的某个地方.

later somewhere in method.

RadioButton selectedRadioButton = (RadioButton) right.getSelectedToggle();
String toogleGroupValue = selectedRadioButton.getText();

这篇关于如何从 ToggleGroup 获取选定的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆