-
Bug
-
Resolution: Fixed
-
P3
-
1.3.0
-
beta2
-
generic, x86
-
generic, windows_nt
Name: krT82822 Date: 09/30/99
When the following code is called
JCheckBox box = new JCheckBox();
box.setSelected(false);
box.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
System.err.println("stateChanged!");
}
}
box.setSelected(false); // this yields an event!
the second 'setSelected(false)' call causes an event to be
fired, although the state of the model factually didn't change.
The solution for the problem is pretty obvious (someone commented
out some source code and did not consider all the consequences):
In the code for the ToggleButtonModel (starting with line 222
in the JDK 1.2.2 sources) you get the following source code --
just look at the first three lines of the method and you will see
the problem: the check for real changes has erroneously been
commented out:
/**
* Sets the selected state of the button.
* @param b true selects the toggle button,
* false deselects the toggle button.
*/
public void setSelected(boolean b) {
// if (this.isSelected() == b) {
// return;
// }
if(group != null) {
// use the group model instead
group.setSelected(this, b);
} else {
if (b) {
stateMask |= SELECTED;
} else {
stateMask &= ~SELECTED;
}
}
// Send ChangeEvent
fireStateChanged();
// Send ItemEvent
fireItemStateChanged(
new ItemEvent(this,
ItemEvent.ITEM_STATE_CHANGED,
this,
this.isSelected() ? ItemEvent.SELECTED : ItemEvent.DESELECTED));
}
---------------
9/30/99 eval1127@eng -- still true in kestrel-beta. Couldn't find existing dupe bug.
(Review ID: 95953)
======================================================================
- duplicates
-
JDK-4382567 setState() now causes stack overflow problems
-
- Closed
-
- relates to
-
JDK-4517913 ButtonGroup allows multiple selected items in 1.4
-
- Closed
-
-
JDK-4485016 JCK14, api/javax_swing/interactive/JTextFieldTests0007, sparc,x86,b73, merlin
-
- Closed
-