質問

Good day

Would like to know how to add radiobuttons to a ButtonGroup by dragging and dropping components on to the frame.

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);

How can I do this by simple dragging and dropping. If I drop the ButtonGroup onto the frame it gets grouped under 'other components' and from there I am not exactly sure how to add radio buttons to the button group.

thanks regards Arian

役に立ちましたか?

解決

you have look at HierarchyListener, on hierarchyChanged event you have add a new JRadioButton to the ButtonGroup, carefully with last know isSelected for concrete JRadioButton

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top