本文介绍了set根据动作命令在按钮组中选择一个特定的jradiobutton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据actionCommand(/特定jradiobutton的名称)setSelected在按钮组中指定一个jradiobutton。

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

可以通过ind.setSelected(true )

it could be done 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);} NOR {group.setSelected(rabbitButton.getModel,true)}

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

是否可以根据操作设置setSelected(true)rabbitButton command()?

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

推荐答案

yourButtonGroup.clearSelection();
yourRadioButton.setSelected(true);

这篇关于set根据动作命令在按钮组中选择一个特定的jradiobutton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 03:49