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()?
yourButtonGroup.clearSelection();
yourRadioButton.setSelected(true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With