Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4713519

1.4 REGRESSION: JComboBox behaves differently in jdk1.3.1 and jdk1.4

XMLWordPrintable

    • mantis
    • x86
    • windows_nt



      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)
      ======================================================================

            mdavidsosunw Mark Davidson (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: