14

再会

想知道如何通过将组件拖放到框架上来将单选按钮添加到 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 放到框架上,它将被分组在“其他组件”下,并且从那里我不确定如何将单选按钮添加到按钮组。

谢谢问候阿里安

4

1 回答 1

4

您已经查看了HierarchyListener,在hierarchyChanged事件中您添加了一个新JRadioButtonButtonGroup,仔细最后知道 isSelected 用于具体JRadioButton

于 2012-01-09T13:54:20.277 回答