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

JList.setSelectedValue(null, ...) doesn't do anything

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 11
    • 1.2.2, 1.4.2, 11
    • client-libs
    • b04
    • generic, x86
    • generic, windows_2000

    Description



      Name: rmT116609 Date: 07/21/2004


      FULL PRODUCT VERSION :
      java version "1.4.2_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
      Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)

      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)


      FULL OS VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      JList.setSelectedValue(null, ...) doesn't do anything

      It would seem that the developer was trying to make the item get unselected with the following code: if(anObject == null) setSelectedIndex(-1);, found at the start of the public void setSelectedValue(Object anObject,boolean shouldScroll) method, however that code is not doing anything.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      no item to be selected
      ACTUAL -
      the previously selected item is still selected

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;

      public class Test {
        public static void main(String[] args) {
          JFrame frame = new JFrame();
          JList list = new JList(new Object[] {"1", "2", "3"});
          frame.getContentPane().add(list);
          System.out.println("Setting selected value to 1");
          list.setSelectedValue("1", true);
          System.out.println("Selected Value: " + list.getSelectedValue());
          System.out.println("Setting selected value to 2");
          list.setSelectedValue("2", true);
          System.out.println("Selected Value: " + list.getSelectedValue());
          System.out.println("Setting selected value to null");
          list.setSelectedValue(null, true);
          System.out.println("Selected Value: " + list.getSelectedValue());
          frame.setSize(500, 500);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      before calling list.setSelectedValue(object, ...); check the value of object and if it is null call clearSelection() instead.
      (Incident Review ID: 218240)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              pbansal Pankaj Bansal (Inactive)
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: