【发布时间】:2015-01-25 13:54:36
【问题描述】:
我已经将单选按钮添加到按钮组,但问题是可以同时选择两个单选按钮!我不知道该怎么办。请帮忙。 这是我当前代码的样子:
JRadioButton rEncrypt, rDecrypt;
ButtonGroup bgroup = new ButtonGroup();
bgroup.add(rEncrypt); bgroup.add(rDecrypt);
rEncrypt = new JRadioButton("Encryption");
rEncrypt.setBackground(bgColor);
rEncrypt.setSelected(true);
pEncrypt = new JPanel();
pEncrypt.setBackground(bgColor);
pEncrypt.add(rEncrypt);
rDecrypt = new JRadioButton("Decryption");
rDecrypt.setBackground(bgColor);
pDecrypt = new JPanel();
pDecrypt.setBackground(bgColor);
pDecrypt.add(rDecrypt);
【问题讨论】:
-
我不太了解 swing,但我很确定它不支持每个组件超过 1 个父级。如果你想让不同位置的按钮表现得像一个组,请手动执行。
标签: java swing radio-button buttongroup