-
Bug
-
Resolution: Won't Fix
-
P3
-
None
-
7u21
-
windows_xp
FULL PRODUCT VERSION :
java version " 1.7.0_21 "
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) Client VM (build 23.21-b01, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
In a Choice control, after selecting a value " A " using the mouse then selecting a value " B " programmatically then selecting a value " A " again using the mouse, no ItemListeners will be invoked. It seems, the component peer still thinks value " A " is selected after value " B " is programmatically selected (and correctly displayed in the control).
REGRESSION. Last worked in version 6u45
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use the attached example. It will display a Choice control with three options, option " one " is selected. If you select option " three " , the selection will be reset to option " one " . Each time the ItemListener is invoked, the selected option along with a timestamp will be printed in a label at the bottom of the frame.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Each time you select " three " the selection should be reset to " one " .
This is the behavior in JRE6.
ACTUAL -
The first time you select " three " the selection will be reset to " one " . Selecting " three " again the selection will remain. When selecting another option ( " one " or " two " ) then selecting " three " the selection will be reset once again.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
public class ChoiceBug extends Frame {
Choice choice;
Label label;
ChoiceBug() {
super( " Choice Bug " );
setSize(300, 200);
setLayout(null);
choice = new Choice();
choice.setSize(150, 30);
choice.setLocation(10, 50);
add(choice);
label = new Label();
label.setSize(250, 30);
label.setLocation(10, 150);
add(label);
choice.addItem( " one " );
choice.addItem( " two " );
choice.addItem( " three " );
choice.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
label.setText((int)System.currentTimeMillis() + " : " + e.getItem());
if(choice.getSelectedIndex() == 2)
choice.select(0);
}
});
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public static void main(String args[]) {
new ChoiceBug().setVisible(true);
}
}
---------- END SOURCE ----------
java version " 1.7.0_21 "
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) Client VM (build 23.21-b01, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
In a Choice control, after selecting a value " A " using the mouse then selecting a value " B " programmatically then selecting a value " A " again using the mouse, no ItemListeners will be invoked. It seems, the component peer still thinks value " A " is selected after value " B " is programmatically selected (and correctly displayed in the control).
REGRESSION. Last worked in version 6u45
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use the attached example. It will display a Choice control with three options, option " one " is selected. If you select option " three " , the selection will be reset to option " one " . Each time the ItemListener is invoked, the selected option along with a timestamp will be printed in a label at the bottom of the frame.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Each time you select " three " the selection should be reset to " one " .
This is the behavior in JRE6.
ACTUAL -
The first time you select " three " the selection will be reset to " one " . Selecting " three " again the selection will remain. When selecting another option ( " one " or " two " ) then selecting " three " the selection will be reset once again.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
public class ChoiceBug extends Frame {
Choice choice;
Label label;
ChoiceBug() {
super( " Choice Bug " );
setSize(300, 200);
setLayout(null);
choice = new Choice();
choice.setSize(150, 30);
choice.setLocation(10, 50);
add(choice);
label = new Label();
label.setSize(250, 30);
label.setLocation(10, 150);
add(label);
choice.addItem( " one " );
choice.addItem( " two " );
choice.addItem( " three " );
choice.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
label.setText((int)System.currentTimeMillis() + " : " + e.getItem());
if(choice.getSelectedIndex() == 2)
choice.select(0);
}
});
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public static void main(String args[]) {
new ChoiceBug().setVisible(true);
}
}
---------- END SOURCE ----------
- relates to
-
JDK-7171412 awt Choice doesn't fire ItemStateChange when selecting item after select() call
-
- Closed
-