e770. determining the selected jradiobutton in a button group.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 13 行

TXT
13
字号
When you ask a button group for the currently selected radio button, it returns the selected radio button's model (rather than the selected radio button itself). Fortunately, the button group maintains the list of buttons and so you can iterate over this list looking for one with the same model. 
    // This method returns the selected radio button in a button group
    public static JRadioButton getSelection(ButtonGroup group) {
        for (Enumeration e=group.getElements(); e.hasMoreElements(); ) {
            JRadioButton b = (JRadioButton)e.nextElement();
            if (b.getModel() == group.getSelection()) {
                return b;
            }
        }
        return null;
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?