I've got the following for
loop creating JRadioButton
s for the ButtonGroup
btgrpDiff
for each of the values in my Difficulty
enum
:
private enum Difficulty {
EASY("Easy"),
MEDIUM("Medium"),
HARD("Hard"),
EXTRA_HARD("Extra Hard");
public final String name;
private Difficulty(String name) {
this.name = name;
}
}
for (Difficulty diff : Difficulty.values()) {
JRadioButton radDiff = new JRadioButton(diff.name);
radDiff.setActionCommand(diff.name);
btgrpDiff.add(radDiff);
panDiff.add(radDiff, "align 50%, shrink 2, wrap");
}
How can I setSelected
for the ButtonGroup
btgrpDiff
outside of the for
loop? I'd like to either set it straight after they're all selected or have a boolean parameter for each difficulty level in my enum to determine whether or not they get set as selected in the for
loop, but I'm not sure which would be best, or how exactly to get the ButtonModel
for the JRadioButton
s.