United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4713519 1.4 REGRESSION: JComboBox behaves differently in jdk1.3.1 and jdk1.4
JDK-4713519 : 1.4 REGRESSION: JComboBox behaves differently in jdk1.3.1 and jdk1.4

Details
Type:
Bug
Submit Date:
2002-07-11
Status:
Resolved
Updated Date:
2002-10-19
Project Name:
JDK
Resolved Date:
2002-10-19
Component:
client-libs
OS:
windows_nt
Sub-Component:
javax.swing
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.1
Fixed Versions:
1.4.2 (mantis)

Related Reports

Sub Tasks

Description

Name: gm110360			Date: 07/11/2002


FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

FULL OPERATING SYSTEM VERSION : Windows NT Version 4.0


A DESCRIPTION OF THE PROBLEM :

Steps.

1. remove all elements in a JCombobox.
2. add new items to the JComboBox.
3. set selected index of combo box as zero.

Result.

in jdk1.3.1 item state change event will be fired always.
in jdk 1.4.0 itemStateChange even will be fired only if the
display string is different from the display String which
was selected before removing all items in the combobox



REGRESSION.  Last worked in version 1.3.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :

1. Load a JComboBox with a list of string values. set
selected index as 0. itemStateChanged event will be
genereated.

2. Remove all items in combo box using combo.removeAllItems

3. Load the the combobox again with the same list of
strings used in step 1. set selected index as 0. This time
itemStateChanged will not be fired in jdk1.4.0 , but in
jdk1.3.1 it is fired.

EXPECTED VERSUS ACTUAL BEHAVIOR :

The itemSstateChanged event should be fired.

This bug can be reproduced always.

---------- BEGIN SOURCE ----------




import javax.swing.* ;
import java.awt.* ;
import java.awt.event.* ;
import java.util.* ;

/**
* author Abhilash K Bhaskaran
* 
* Click on "reload" button multiple times in jdk1.3.1 and
* jdk1.4.0 to see the result.
*/
public class TEST extends JFrame{
	private JButton reload ;
	private JComboBox combo ;

	public void init(){
	    combo = new JComboBox() ;
		combo.addItemListener( new ItemListener(){
				public void itemStateChanged( ItemEvent event ){
				  if (null != combo.getSelectedItem() &&
				  		event.getStateChange() ==
ItemEvent.SELECTED){
					System.out.println("S:"+
combo.getSelectedItem()) ;
				  }
				}
			} );
		reload = new JButton("reload") ;
		reload.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e){
					loadCombo() ;
				}
			}) ;
		JPanel panel = new JPanel(new BorderLayout()) ;
		panel.add(combo,BorderLayout.NORTH) ;
		panel.add(reload,BorderLayout.SOUTH) ;
		getContentPane().add(panel) ;
	}
	public void loadCombo(){
		combo.removeAllItems() ;
		for (int iCount = 0 ; iCount <10 ; iCount++){
			String strItem = "Item-"+iCount ;
	    	combo.addItem(strItem) ;
		}

		try{
			combo.setSelectedIndex(0) ;
		}catch(Exception e){}
	}
	public static final void main(String args[]){
		TEST app = new TEST() ;
		app.init() ;
		app.setSize(100,100) ;
		app.setVisible(true) ;
		app.loadCombo() ;
	}
}
---------- END SOURCE ----------

Release Regression From : 1.3.0_03
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Review ID: 139926) 
======================================================================

                                    

Comments
EVALUATION

The semantics of firing an itemStateChanged event changed in 1.4 so that the event will be fired only when the selected item changes. The actionEvent will always be fired.

However, the removal of items and repopulating the list touches a similar bug reported in 4712013 in which the cached selected item in JComboBox is not cleared when removeAllItems is called. This could be the problem that the submitter is experiencing. Not a showstopper for Hopper but will consider it for Mantis.
###@###.### 2002-07-11

The fixes to 4712013 and 4741130 will enable the itemRemoved method and force the selection events. Unfortunately, multiple events are fired indescriminately since the check for the item selection change is not made. An additional fix would be to check to see that the item selection has been made before calling selectedItemChanged and the DefaultComboBox.addElement should only fire the intervalAdded event after a selection has been made.
###@###.### 2002-10-02
                                     
2002-10-02
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mantis

FIXED IN:
mantis

INTEGRATED IN:
mantis


                                     
2004-06-14



Hardware and Software, Engineered to Work Together