The JComboBox doesn´t work correctly when call funtion RemoveAllItems

XMLWordPrintable

      FULL PRODUCT VERSION :
      jp_1.4.2.11, 1.5.0_07

      ADDITIONAL OS VERSION INFORMATION :
      windows 2000, windows 98, windows xp, linux debian sarge

      A DESCRIPTION OF THE PROBLEM :
      it is a problem that happens on the virtual machines after the version 1.4.1. When you click over a JcomboBox and inside the event you call the method removeallItems(); it creates a new actionEvent that is carried by the listener of the component, that shouldn´t happen cause I am just using a method, that doesn´t happen on the version 1.4.1 of the JVM

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :

      I made an example showing the bug of the newer JVM's, I suggest you that you
      try the example on the JVM 1.4.1 and then in the new ones. I include the
      whole example which is based on the java archives. The class that holds the main method is Application1.java put the archives on the same folder named test_combo;
      Compile both archives to create the Application1.class and the Frame1.class
      and then run it.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The idea is when you call the method jComboBox1.RemoveAllIItems(); nothing
      else should happen but just remove all items from the combo box, my program
      was developed using the jvm 1.4.1 and it worked correclty. I made updates on my JVM and my program didn't work correctly anymore. On the new JVM when you call the method jComboBox1.RemoveAllIItems(); creates an additional action that is carried by the ActionListener of the ComoBox and that is not a correct behavior


      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      Application1.java and Frame1.java
      //////Application1.java
      package test_combo;
      import javax.swing.UIManager;
      import java.awt.*;
      public class Application1 {
        boolean packFrame = false;
        public Application1() {
          Frame1 frame = new Frame1();
         if (packFrame) {
            frame.pack();
          }
          else {
            frame.validate();
          }
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
          Dimension frameSize = frame.getSize();
          if (frameSize.height > screenSize.height) {
            frameSize.height = screenSize.height;
          }
          if (frameSize.width > screenSize.width) {
            frameSize.width = screenSize.width;
          }
          frame.setLocation((screenSize.width - frameSize.width) / 2,
      (screenSize.height - frameSize.height) / 2);
          frame.setVisible(true);
        }
        public static void main(String[] args) {
          try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          }
          catch(Exception e) {
            e.printStackTrace();
          }
          new Application1();
        }
      }
      ////Frame1.java
      package test_combo;
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      public class Frame1 extends JFrame {
        JPanel contentPane;
        JComboBox jComboBox1 = new JComboBox();
        FlowLayout flowLayout1 = new FlowLayout();
        JLabel jLabel1 = new JLabel();
        JLabel veces = new JLabel();
        JButton jButton1 = new JButton();
         static int count=-1;
        JTextArea jTextArea1 = new JTextArea();
        JTextField jTextField1 = new JTextField();
        //Construct the frame
        public Frame1() {
          enableEvents(AWTEvent.WINDOW_EVENT_MASK);
          try {
            jbInit();
          }
          catch(Exception e) {
            e.printStackTrace();
          }
        }
        //Component initialization
        private void jbInit() throws Exception {
          contentPane = (JPanel) this.getContentPane();
          contentPane.setLayout(flowLayout1);
          this.setSize(new Dimension(452, 150));
          this.setTitle("Test combo");
          jComboBox1.addActionListener(new Frame1_jComboBox1_actionAdapter(this));
          jLabel1.setText("went action Listener:");
          veces.setRequestFocusEnabled(true);
          veces.setText("0");
          jButton1.setText("RemoveAllItems()");
          jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
          //jLabel2.setText("");
          jTextArea1.setText("JVM 1.4.1 works correctly it doesn\'t go to the
      action Listener");
          jTextField1.setText("On newer versions of JVM work incorrectly cause
      creates an action");
          contentPane.add(jComboBox1, null);
          contentPane.add(jButton1, null);
          contentPane.add(jLabel1, null);
          contentPane.add(veces, null);
          contentPane.add(jTextArea1, null);
          contentPane.add(jTextField1, null);
          for(int i=0;i<10;i++)
            this.jComboBox1.addItem(""+(i+1));
        }
        protected void processWindowEvent(WindowEvent e) {
          super.processWindowEvent(e);
          if (e.getID() == WindowEvent.WINDOW_CLOSING) {
            System.exit(0);
          }
        }
        void jComboBox1_actionPerformed(ActionEvent e) {
            count++;
            veces.setText(""+count);
        }
        void jButton1_actionPerformed(ActionEvent e) {
          this.jComboBox1.removeAllItems(); ///calling just the function
        }
      }
      class Frame1_jComboBox1_actionAdapter implements
      java.awt.event.ActionListener {
        Frame1 adaptee;

        Frame1_jComboBox1_actionAdapter(Frame1 adaptee) {
          this.adaptee = adaptee;
        }
        public void actionPerformed(ActionEvent e) {
          adaptee.jComboBox1_actionPerformed(e);
        }
      }
      class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener
      {
        Frame1 adaptee;

        Frame1_jButton1_actionAdapter(Frame1 adaptee) {
          this.adaptee = adaptee;
        }
        public void actionPerformed(ActionEvent e) {
          adaptee.jButton1_actionPerformed(e);
        }
      }
      ---------- END SOURCE ----------

            Assignee:
            Unassigned
            Reporter:
            Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: