JDK-8033936 : java.awt.List events are not sent properly to handleEvent or ItemListener
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7,7u5,8,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86
  • Submitted: 2012-08-17
  • Updated: 2016-04-28
  • Resolved: 2016-03-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b116Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
1.7.0_05-b06

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7600]

A DESCRIPTION OF THE PROBLEM :
Events passed to handleEvent or ItemListener for a java.awt.List are incorrect.

REGRESSION.  Last worked in version 6u31

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a java.awt.List Component with preselected items.  Then select or deselect items and print the result event passed to handle event using the toString method.  the information contained in the event will be incorrect in terms of the index of the item being interacted with and the id of event (Event.LIST_SELECT or Event.LIST_DESELECT).

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect to see the correct event information.
ACTUAL -
Incorrect event information.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
None just incorrect results.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
/*
See http://www.stat.tamu.edu/~west/listtest.html
*/

import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;

public class ListExample extends java.applet.Applet{

TextArea ta = new TextArea("",5,50,TextArea.SCROLLBARS_BOTH);
List variables;

public void init(){
	setLayout(new BorderLayout());
	variables = new List(7,true);
	variables.addItem("One");
	variables.addItem("Two");
	variables.addItem("Three");
	variables.addItem("Four");
	variables.select(0);
	variables.select(1);
	variables.select(2);
	variables.select(3);
	add("Center",variables);
	add("South",ta);
}

  public boolean handleEvent(Event e) {
  	if(e.target instanceof List){
		if (e.id == Event.LIST_DESELECT) {
		  ta.append("List deselected at index "+e.arg.toString());
		}else if(e.id == Event.LIST_SELECT) {
		  ta.append("List selected at index "+e.arg.toString());
		}
		ta.append("\n");
	}
	return super.handleEvent(e);
  }

}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
The only workaround I have found is to store the selected indexes after each event in another vector and then compare it each time with the current value from the getSelectedIndexes method for the List.

SUPPORT :
YES

Comments
regression of JDK-6806217
25-03-2016

Looks like this is a regression of JDK-6806217. When I click on the List from the bug description the focus will not be moved to the clicked element and this causes a deselectEvent to have incorrect index.
07-07-2014

Release team: Approved for deferral.
11-02-2014

JDK8: SQE OK to defer
10-02-2014

8-defer-request: not a jck, not a critical issue.
07-02-2014