3
In the swing of Java, a user can select more than one radio button simultaneously, so this does not happen, one can do:
private void radio1ActionPerformed(java.awt.event.ActionEvent evt) {
if (radio1.isSeleced()) {
radio2.isSelected(false);
}
}
But this is very impractical, imagine a situation that requires dozens of radio buttons, it would be too much work.
Is there any other way to do what I wish? I thought I’d use one foreach putting all radio buttons inside a vector, but I couldn’t abstract anything.
Aren’t you forgetting to group the
JRadioButton
in aButtonGroup
No? The standard behavior of a Radiobutton in a Group is to keep only one selected.– Wakim