我想基于actionCommand(/特定jradiobutton的名称)setSelected一个按钮组中的特定jradiobutton.
可以使用usind .setSelected(true)完成
例如,
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);
现在..没有,
{rabbitButton.setSelected(true);}否{group.setSelected(rabbitButton.getModel,true)}
有没有一种基于动作command()的setSelected(true)RabbitButton的方法?
解决方法:
yourButtonGroup.clearSelection();
yourRadioButton.setSelected(true);
标签:jradiobutton,buttongroup,java,swing
来源: https://codeday.me/bug/20191011/1889169.html