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

method Choice.insert(String item, int index) incorrectly changes selected item

XMLWordPrintable

    • sparc
    • solaris_2.5



      Name: dsC58869 Date: 04/13/98



      The method java.awt.Choice.insert(String item) works wrong
      while inserting item. It should adjust the selected item index,
      otherwise the selected item may change.


      ==== Here is the test demonstrating the bug ====
      import java.awt.*;

      public class Test{
          
          public static void main(String[] args){
      String item0 = "Item 0";
      String item1 = "Item 1";
      String item2 = "Item 2";
      Choice ch = new Choice();
      ch.add(item0);
      ch.add(item1);
      ch.add(item2);
      ch.select(item1);
      System.out.println("Selected item : " + ch.getSelectedItem());
      System.out.println("Selected index: " + ch.getSelectedIndex());
      System.out.println("Insert new item between Item 0 and Item 1");
      String newitem = "New Item";
      ch.insert(newitem, 1);
      System.out.println("Selected item : " + ch.getSelectedItem());
      System.out.println("Selected index: " + ch.getSelectedIndex());
      if(ch.getSelectedItem().equals(item1) && ch.getSelectedIndex() == 2)
      System.out.println("OKAY");
      else
      System.out.println("FAILED: selected item was changed");
          }
      }


      ==== Here is the output of the test ====
      %
      java Test
      Selected item : Item 1
      Selected index: 1
      Insert new item between Item 0 and Item 1
      Selected item : Item 0
      Selected index: 0
      FAILED: selected item was changed
      ^C
      ======================================================================
       Justification:
      There is no reason to change selected item

      ======================================================================

            dmendenhsunw David Mendenhall (Inactive)
            dsilaev Dmitri Silaev
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: