中易网

java让单选按钮默认选中的方法

答案:5  悬赏:60  
解决时间 2021-01-17 08:08
  • 提问者网友:雾里闻花香
  • 2021-01-16 20:50
java让单选按钮默认选中的方法
最佳答案
  • 二级知识专家网友:撞了怀
  • 2021-01-16 22:05
ButtonGroup bg=new ButtonGroup();
JRadioButtonb1=new JRadioButton();
JRadioButtonb2=new JRadioButton();
bg.add(b1);
bg.add(b2);
b1.setSelected(true);//默认选中的是b1

JButton表示的是普通按钮,JRadioButton才是单选按钮。
b1,b2加入了ButtonGroup,是互斥的,默认只能选中一个。
全部回答
  • 1楼网友:轻雾山林
  • 2021-01-17 02:39
<html><body>
<input type = 'radio' name = 'name' checked = true>
<input type = 'radio' name = 'name'>
</body></html>
  • 2楼网友:白昼之月
  • 2021-01-17 01:11
<html><body>
<input type = 'radio' name = 'name' checked>
<input type = 'radio' name = 'name'>
</body></html>
这样就搞定了
  • 3楼网友:山有枢
  • 2021-01-17 00:05
JRadioButton类的方法
setSelected()
参数是true
  • 4楼网友:七十二街
  • 2021-01-16 23:37
JRadioButton(Icon icon, boolean selected)
创建一个具有指定图像和选择状态的单选按钮,但无文本。
JRadioButton(String text, boolean selected)
创建一个具有指定文本和选择状态的单选按钮。
JRadioButton(String text, Icon icon, boolean selected)
创建一个具有指定的文本、图像和选择状态的单选按钮。
=================================================
这3种构造函数都可以生成默认选种的单选按钮
举例:
new JRadioButton("默认选种的",true);
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息