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

awt.List.select w/ param = -1 last item in list gets selected

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.7
    • client-libs
    • None
    • sparc
    • solaris_7

      In awt.List select(int index) get unexpected behavior when the index param
      is equal to -1. The last item in the list gets selected. When other invalid
      values (-2) are used the call is ignored.

      The same problem occurs with the deselect(int index) method.
      If you add a few items to the list and call deselect with -1 as the index it
      deselects the last item in the list.

      /*
       * @(#)SelectTest.java
       * @author JTG SQE East 5/20/99
       * @version 1.0
       *
       * java.awt.Label.select method tests
       */

      import java.awt.*;
      import java.io.*;
      import java.awt.peer.ListPeer;

      /**
       * Method: java.awt.List.select
       * <p>Syntax: public void select(int index)
       * <p>Params: int index
       * <p>Return: none
       * <p>Exception: none
       * <p>Pupose: selects an item in the list
       */

      public class SelectTest extends Frame
      {
         List l;

         SelectTest()
         {
            super("select() Test");
            l = new List();
         }

         public static void main(String[] args)
         {
            SelectTest s = new SelectTest();
           
            boolean fail = false;

            s.setSize(500, 500);
            s.setVisible(true);
            s.add(s.l);
            s.l.addItem("Item1");
            s.l.addItem("Item2");
            s.l.addItem("Item3");
            System.out.println("index count " + s.l.getItemCount());
            /* These should not select anything */
            
            System.out.println("test 1, param index = -1");
            s.l.select(-1); /* bug here */
                 
            System.out.println("select index " + s.l.getSelectedIndex());

            if( s.l.getSelectedIndex() != -1 )
            {
               fail = true;
               System.out.println("fail 1");
            }

            for (int i = 0; i < s.l.getItemCount(); ++i) {
      s.l.deselect(i);
            }
            
            System.out.println("test 2, param index = -2");
            s.l.select(-2);

            System.out.println("select index " + s.l.getSelectedIndex());
            if( s.l.getSelectedIndex() != -1 )
            {
               fail = true;
               System.out.println("fail 2");
            }

            if( fail )
            {
               System.out.println("Test for List.select Failed");
               System.exit(1);
            }
            else
            {
               System.out.println("Test for List.select Passed");
               System.exit(0);
            }
         }
      }

            ehawkessunw Eric Hawkes (Inactive)
            mcolburnsunw Michael Colburn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: