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

java.awt.Choice doesn't work correctly after calling Choice.select( int )

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description

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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      There are 2 items ("A","B") in Choice and I select the second item ("B"). Then I call code choice.select ( 0 ) to make choice select the first one("A"). Finally, I select the second item again and call choice.getSelectedItem() and also choice.getSelectedIndex().

      The problem is choice.getSelectedItem() and choice.getSelectedIndex() return "A" and 0 consecutively but in Java 1.6 they return "B" and 1 consecutively.

      REGRESSION. Last worked in version 6u31

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Create java.awt.choice and add 2 String items in the choice, {"A","B"}.
      2) Add a button which following code for ActionListener.
      2.1 print out choice.getSelectedItem().
      2.2 print out choice.getSelectedIndex().
      2.3 call choice.select( 0 ).
      3) Start program.
      4) Select item "B" in the choice then press the button.
      Actual Result
      4.1 print out "B" -> correct
      4.2 print out 1 -> correct
      4.3 choice move to select index 0 which is "A" -> correct.
      5) Select item "B" again.
      6) Press the button.
      Actual Result
      6.1 print out "A" -> INCORRECT.
      6.2 print out 0 -> INCORRECT.
      6.3 choice move to select index 0 which is "A" -> correct.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      For step 6) the expected result are
      6.1 print out "B" as previous selected item is "B" in step (5).
      6.2 print out 1 as previous selected index is 1 in step (5).
      6.2 choice move to select index 0 which is "A".
      ACTUAL -
      For step 6) the actual result are
      6.1 print out "A".
      6.2 print out 0.
      6.3 choice move to select index 0 which is "A".

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package client;

      import java.awt.Button;
      import java.awt.Choice;
      import java.awt.FlowLayout;
      import java.awt.Frame;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      public class TestChoice {

      public static Choice c1;
      public static Button b1;

      public static void main(String[] args) {
      Frame f = new Frame("Test Choice");
      f.setLayout( new FlowLayout() );
      c1 = new Choice();
      b1 = new Button("reset");
      b1.addActionListener( new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      System.out.println( c1.getSelectedItem() + " " + c1.getSelectedIndex() );
                      c1.select( 0 );
      }
      });
      c1.add("A");
      c1.add("B");
      f.add( c1 );
      f.add( b1 );
      f.pack();
      f.setVisible( true );
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Just replace java.awt.Choice with javax.swing.JComboBox. Unfortunately, we can't do this as we still support some of our clients who still using Microsoft JVM which does not contain java.swing package.

      SUPPORT :
      YES

        Attachments

          Activity

            People

            Assignee:
            aivanov Alexey Ivanov
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: