将JRadioButton添加到RadioButton组

时间:2012-01-09 13:43:54

标签: java swing netbeans-7 jradiobutton buttongroup

美好的一天

想知道如何通过将组件拖放到框架上来将单选按钮添加到ButtonGroup。

JRadioButton male = new JRadioButton("Male");
JRadioButton female = new JRadioButton("Female");
ButtonGroup bg = new ButtonGroup();
bg.add(male);
bg.add(female);
pane.add(male);
pane.add(female);

如何通过简单的拖放操作来完成此操作。如果我将ButtonGroup放到框架上,它会在“其他组件”下分组,从那里我不确定如何将单选按钮添加到按钮组。

感谢 关于阿里安

1 个答案:

答案 0 :(得分:4)

你看{4}} HierarchyListener事件,hierarchyChanged事件你已经JRadioButton添加新的ButtonGroup,仔细阅读最后知道isSelected for concrete JRadioButton