-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
6
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.5.0_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
To conform the specification, when setSelected(false) is called on a JRadioButton, the state should be set to false. I understand that ButtonGroup requires that at least one button is selected. The solution is thus to setSelected(true) another button. This is a very useful feature when there are only two buttons (in which case it would always toggle to the other). When there are more than two, it could setSelected(true) the next button in order of addition to the group.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
JRadioButton b1 = new JRadioButton("Button 1");
b1.setSelected(true);
JRadioButton b2 = new JRadioButton("Button 2");
ButtonGroup group = new ButtonGroup();
group.add(b1);
group.add(b2);
panel.add(b1);
panel.add(b2);
b1.setSelected(false);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
b1 would be deselected, and b1 would be selected.
ACTUAL -
b1 is still selected.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
//public domain
import javax.swing.*;
import java.awt.*;
public class JRadioButtonTesting
{
public static void main(String [] args)
{
JFrame frame = new JFrame();
JPanel panel = new JPanel();
frame.getContentPane().add(panel);
JRadioButton b1 = new JRadioButton("Button 1");
b1.setSelected(true);
JRadioButton b2 = new JRadioButton("Button 2");
ButtonGroup group = new ButtonGroup();
group.add(b1);
group.add(b2);
panel.add(b1);
panel.add(b2);
b1.setSelected(false);
frame.pack();
frame.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Manually setSelected(true) on the other button (which requires detecting which one isn't selected).
java version "1.5.0_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
To conform the specification, when setSelected(false) is called on a JRadioButton, the state should be set to false. I understand that ButtonGroup requires that at least one button is selected. The solution is thus to setSelected(true) another button. This is a very useful feature when there are only two buttons (in which case it would always toggle to the other). When there are more than two, it could setSelected(true) the next button in order of addition to the group.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
JRadioButton b1 = new JRadioButton("Button 1");
b1.setSelected(true);
JRadioButton b2 = new JRadioButton("Button 2");
ButtonGroup group = new ButtonGroup();
group.add(b1);
group.add(b2);
panel.add(b1);
panel.add(b2);
b1.setSelected(false);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
b1 would be deselected, and b1 would be selected.
ACTUAL -
b1 is still selected.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
//public domain
import javax.swing.*;
import java.awt.*;
public class JRadioButtonTesting
{
public static void main(String [] args)
{
JFrame frame = new JFrame();
JPanel panel = new JPanel();
frame.getContentPane().add(panel);
JRadioButton b1 = new JRadioButton("Button 1");
b1.setSelected(true);
JRadioButton b2 = new JRadioButton("Button 2");
ButtonGroup group = new ButtonGroup();
group.add(b1);
group.add(b2);
panel.add(b1);
panel.add(b2);
b1.setSelected(false);
frame.pack();
frame.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Manually setSelected(true) on the other button (which requires detecting which one isn't selected).