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

Choice control doesn't respond properly after call to select(pos)

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.7.0_03"
      Java(TM) SE Runtime Environment (build 1.7.0_03-b05)
      Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      If a user selects a value in a Choice control, the control is then reset programatically via control.select(0), and the user then reselects the same value, the item state change callback is not fired and control.getSelectedIndex() will return 0 instead of the index of the selected value. The control visually shows the proper selected item.

      This behavior did not occur in prior java versions up through Java 6.

      REGRESSION. Last worked in version 6u31

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute provided test Applet under Java 6 and Java 7.

      1. Select value "BBB" from Choice.
      2. Press "Index" button, current selected index/value of Control "BBB" (1) is printed to System.out
      3. Press "Reset" button, control displays "AAA" again.
      4. Select value "BBB" from Choice
      5. Press "Index" button again, "BBB" (1) is printed again


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Output from run on 1.6.0_31

      Java Version: 1.6.0_31
      Choice changed BBB (1)
      Choice is BBB (1)
      Reset choice to 0
      Choice changed BBB (1)
      Choice is BBB (1)
      ACTUAL -
      Output from run on 1.7.0_03

      Note that "Choice changed" output from item state callback is missing following the "Reset choice..." output. The selected output from the second press of the "Index" button reports "AAA" (0) even though the control visually displays "BBB".

      Java Version: 1.7.0_03
      Choice changed BBB (1)
      Choice is BBB (1)
      Reset choice to 0
      Choice is AAA (0)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.applet.Applet;
      import java.awt.Button;
      import java.awt.Choice;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.awt.event.ItemEvent;
      import java.awt.event.ItemListener;


      public class ChoiceBug extends Applet implements ActionListener, ItemListener {

      Choice c;
      Button reset;
      Button index;

      public void start()
      {
      String ver = System.getProperty("java.version");
      System.out.println("Java Version: "+ver);

      c = new Choice();
      c.add("AAA");
      c.add("BBB");
      c.add("CCC");
      c.addItemListener(this);

      add(c);

      reset = new Button("Reset");
      reset.addActionListener(this);

      add(reset);

      index = new Button("Index");
      index.addActionListener(this);

      add(index);
      }

      public void actionPerformed(ActionEvent arg0) {
      Object src = arg0.getSource();

      if (src == reset) {
      c.select(0);
      System.out.println("Reset choice to 0");
      } else if (src == index)
      System.out.println("Choice is "+c.getSelectedItem()+" ("+c.getSelectedIndex()+")");
      }

      public void itemStateChanged(ItemEvent arg0) {
      System.out.println("Choice changed "+c.getSelectedItem()+" ("+c.getSelectedIndex()+")");
      }
      }
      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              pchelko Petr Pchelko (Inactive)
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: