Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setSelected a specific jradiobutton in a buttongroup based on action command

i want to setSelected a speicfic jradiobutton in a buttongroup based on the actionCommand(/name of the specific jradiobutton).

it could be done usind .setSelected(true)

for example,

JRadioButton rabbitButton = new JRadioButton("rabbit");
 rabbitButton .setActionCommand("rabbit");
JRadioButton pigButton = new JRadioButton("pig");
 pigButton .setActionCommand("pig");

ButtonGroup group = new ButtonGroup();

group.add(rabbitButton);
group.add(pigButton);

now.. without ,

{ rabbitButton.setSelected(true);} NOR {group.setSelected(rabbitButton.getModel,true)}

is there a way to setSelected(true) rabbitButton based on the action command()?

like image 220
Neon Shri Avatar asked Jan 16 '12 04:01

Neon Shri


1 Answers

yourButtonGroup.clearSelection();
yourRadioButton.setSelected(true);
like image 196
ThatBuffDude Avatar answered Nov 15 '22 04:11

ThatBuffDude