如何在java中管理两个JRadioButtons,以便一次只能选择其中一个 [英] How to manage two JRadioButtons in java so that only one of them can be selected at a time

查看:542
本文介绍了如何在java中管理两个JRadioButtons,以便一次只能选择其中一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在java中管理两个JRadioButtons,以便一次只能选择其中一个? java中是否有任何方法可以解决这个问题,或者你需要构建自己的逻辑?

How to manage two JRadioButtons in java so that only one of them can be selected at a time? Is there any method in java to take care of this or you need to build your own logic?

推荐答案

你必须添加它们在 ButtonGroup

ButtonGroup group = new ButtonGroup();
group.add(birdButton);
group.add(catButton);

确保在使用新的 JRadioButton <创建按钮后添加此代码/ code>构造函数,视情况而定。

Ensure you add this code after the buttons are created using the new JRadioButton constructors, as appropriate.

这篇关于如何在java中管理两个JRadioButtons,以便一次只能选择其中一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆