JDK-8040621 : ItemListener not invoked on java.awt.Choice
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7u21
  • Priority: P3
  • Status: Resolved
  • Resolution: Won't Fix
  • OS: windows_xp
  • Submitted: 2013-05-03
  • Updated: 2014-11-19
  • Resolved: 2014-05-28
Related Reports
Relates :  
Description
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 ----------
Comments
Closing as Will Not Fix, see justification above.
28-05-2014

The problem is not reproducible on jdk8 and jdk9. It was fixed by JDK-7171412. We do not have plans to backport JDK-7171412 to jdk7, please use jdk8 or jdk9 instead.
28-05-2014

Not reproducible in 8 or 9, also XP is not supported there. Transferring to sustaining for further evaluation.
16-04-2014

The problem is reproducible only on jdk7, jdk8 does not have this problem.
16-04-2014