【发布时间】:2016-06-01 21:29:12
【问题描述】:
在一个项目中,我将 ItemListener 添加到一组 JcheckBox 和 JRadioButtons 中。
我希望当用户点击已选择的 JRadioButton 时,它会被取消选择。
对于我知道的唯一方法是获取相应的 ButtonGroup,然后调用 clearSelection() 方法。 但在 itemStateChanged() 方法中,我有 JtoggleButton option=(JtoggleButton)event.getSource();
所以选项指的是 JRadioButton 或 JcheckBox。我已经搜索过,但我找不到为 JRadioButton 获取 ButtonGroup 的方法。
【问题讨论】:
标签: java swing jcheckbox jradiobutton