ButtonGroup bg = new ButtonGroup();
            bg.add(jRadioButtonColor);
            bg.add(jRadioButtonBlackWhite);
            jPanelColor.add(getJRadioButtonColor(), null);
            jPanelColor.add(getJRadioButtonBlackWhite(), null);
这样把单选按钮加入到ButtonGroup中没有错误吧,为什么不能实现只选中一个呢?
各位大侠帮帮忙!

解决方案 »

  1.   

    你的 jRadioButtonColor 和 jRadioButtonBlackWhite
    是不是在 getJRadioButtonColor() 和 getJRadioButtonBlackWhite() 方法中初始化的也就是说 jRadioButtonColor 和 jRadioButtonBlackWhite 在 add 到 bg 中的时候实际上是 null ?你反过来试试 
                ButtonGroup bg = new ButtonGroup();
                jPanelColor.add(getJRadioButtonColor(), null);
                jPanelColor.add(getJRadioButtonBlackWhite(), null);
                bg.add(jRadioButtonColor);
                bg.add(jRadioButtonBlackWhite);
      

  2.   

    嗯,是用get方法初始化的,在add的时候也写成bg.add(getJRadioButtonBlackWhite())就可以了,嘿嘿