将 JRadioButton 添加到 RadioButton 组

日安

想知道如何通过将组件拖放到框架上来向 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

你看看 HierarchyListener,在事件上你已经添加了一个新的,仔细地与最后一个知道是选择具体hierarchyChangedJRadioButtonButtonGroupJRadioButton


答案 2

推荐