adding JRadioButton to RadioButton group
Asked Answered
L

1

14

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

Linnet answered 9/1, 2012 at 13:43 Comment(0)
Q
4

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

Quarterhour answered 9/1, 2012 at 13:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.