United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4368570 : unix: Clicking on a List item that is already selected does not deselect it

Details
Type:
Bug
Submit Date:
2000-09-06
Status:
Closed
Updated Date:
2003-10-22
Project Name:
JDK
Resolved Date:
2003-06-06
Component:
client-libs
OS:
linux,generic
Sub-Component:
java.awt
CPU:
itanium,x86,generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.3.0,1.4.2,5.0
Fixed Versions:
5.0 (tiger)

Related Reports

Sub Tasks

Description

Name: iaR10016			Date: 09/06/2000



JDK version:
java version "1.3.0rc1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-b17)
Java HotSpot(TM) Client VM (build 1.3.0rc1-b17, mixed mode)

Java 2 Platform SE v1.3 specification reads about List item selecting:

...
Clicking on an item that isn't selected selects it.
Clicking on an item that is already selected deselects it.
...

In Linux JDK 1.3 and Solaris JDK 1.3 clicking on selected List item does not
deselect it.

The following test example creates frame with List component. By clicking button
"Selected Item" you can print current selected item index. If you click on item that is
already selected and then click on "Selected Item" button, you can see that this item
does not become unselected.

------------------------ test.java --------------------------------

import java.awt.*;
import java.awt.event.*;

public class test extends Frame implements ActionListener
{
    List aList;
    void init() {
        aList= new List();
        aList.add("Test item1");
        aList.add("Test item2");
        aList.add("Test item3");
        Button aButton = new Button("Selected Item");
        aButton.addActionListener(this);
        Panel aPanel = new Panel();
        aPanel.add(aList);
        aPanel.add(aButton);
        setSize(200,200);
        add(aPanel);
    }

    public static void main(String [] argv)
    {
        test t = new test();
        t.init();
        t.setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        System.out.println("Selected item is " + aList.getSelectedIndex());
    }
}

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

                                    

Comments
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b09

VERIFIED IN:
tiger-beta


                                     
2004-06-14
SUGGESTED FIX



Name: dkR10074			Date: 07/22/2003


------- List.java -------
*** //C/Tools/forte4j/platform/intel-win/bin/util/tmp/sccs.001808       Mon May 12
14:47:14 2003
--- List.java   Mon May 12 14:45:49 2003
***************
*** 45,56 ****
   * <img src="doc-files/List-1.gif"
   * alt="Shows a list containing: Venus, Earth, JavaSoft, and Mars. Javasoft is
selected." ALIGN=center HSPACE=10 VSPACE=7>
   * <p>
!  * Clicking on an item that isn't selected selects it. Clicking on
   * an item that is already selected deselects it. In the preceding
   * example, only one item from the scrolling list can be selected
   * at a time, since the second argument when creating the new scrolling
!  * list is <code>false</code>. Selecting an item causes any other
!  * selected item to be automatically deselected.
   * <p>
   * Note that the list in the example shown was created with four visible
   * rows.  Once the list has been created, the number of visible rows
--- 45,57 ----
   * <img src="doc-files/List-1.gif"
   * alt="Shows a list containing: Venus, Earth, JavaSoft, and Mars. Javasoft is
selected." ALIGN=center HSPACE=10 VSPACE=7>
   * <p>
!  * If the List allows multiple selections, then clicking on
   * an item that is already selected deselects it. In the preceding
   * example, only one item from the scrolling list can be selected
   * at a time, since the second argument when creating the new scrolling
!  * list is <code>false</code>. If the List does not allow multiple
!  * selections, selecting an item causes any other selected item
!  * to be deselected.
   * <p>
   * Note that the list in the example shown was created with four visible
   * rows.  Once the list has been created, the number of visible rows
***************
*** 399,404 ****
--- 400,407 ----
  
      /**
       * Removes the first occurrence of an item from the list.
+      * If the specified item is selected, and is the only selected 
+      * item in the list, the list is set to have no selection.
       * @param        item  the item to remove from the list
       * @exception    IllegalArgumentException
       *                     if the item doesn't exist in the list
***************
*** 415,422 ****
      }
  
      /**
!      * Remove the item at the specified position
       * from this scrolling list.
       * @param      position   the index of the item to delete
       * @see        #add(String, int)
       * @since      JDK1.1
--- 418,427 ----
      }
  
      /**
!      * Removes the item at the specified position
       * from this scrolling list.
+      * If the item with the specified position is selected, and is the 
+      * only selected item in the list, the list is set to have no selection.
       * @param      position   the index of the item to delete
       * @see        #add(String, int)
       * @since      JDK1.1
***************
*** 438,446 ****
  
      /**
       * Gets the index of the selected item on the list,
!      * @return        the index of the selected item, or
!      *                     <code>-1</code> if no item is selected,
!      *                     or if more that one item is selected
       * @see           #select
       * @see           #deselect
       * @see           #isIndexSelected
--- 443,452 ----
  
      /**
       * Gets the index of the selected item on the list,
!      * 
!      * @return        the index of the selected item; 
!      *                if no item is selected, or if multiple items are 
!      *                selected, <code>-1</code> is returned.  
       * @see           #select
       * @see           #deselect
       * @see           #isIndexSelected
***************
*** 452,460 ****
  
      /**
       * Gets the selected indexes on the list.
!      * @return        an array of the selected indexes
!      *                of this scrolling list; if no items are 
!      *                selected, a zero-length array is returned
       * @see           #select
       * @see           #deselect
       * @see           #isIndexSelected
--- 458,466 ----
  
      /**
       * Gets the selected indexes on the list.
!      * 
!      * @return        an array of the selected indexes on this scrolling list; 
!      *                if no item is selected, a zero-length array is returned. 
       * @see           #select
       * @see           #deselect
       * @see           #isIndexSelected
***************
*** 469,476 ****
  
      /**
       * Gets the selected item on this scrolling list.
!      * @return        the selected item on the list,
!      *                     or <code>null</code> if no item is selected
       * @see           #select
       * @see           #deselect
       * @see           #isIndexSelected
--- 475,484 ----
  
      /**
       * Gets the selected item on this scrolling list.
!      * 
!      * @return        the selected item on the list; 
!      *                if no item is selected, or if multiple items are 
!      *                selected, <code>null</code> is returned.  
       * @see           #select
       * @see           #deselect
       * @see           #isIndexSelected
***************
*** 482,489 ****
  
      /**
       * Gets the selected items on this scrolling list.
!      * @return        an array of the selected items
!      *                            on this scrolling list
       * @see           #select
       * @see           #deselect
       * @see           #isIndexSelected
--- 490,498 ----
  
      /**
       * Gets the selected items on this scrolling list.
!      * 
!      * @return        an array of the selected items on this scrolling list;
!      *                if no item is selected, a zero-length array is returned. 
       * @see           #select
       * @see           #deselect
       * @see           #isIndexSelected
***************
*** 498,504 ****
      }
  
      /**
!      * Returns the selected items on the list in an array of objects.
       * @see ItemSelectable
       */
      public Object[] getSelectedObjects() {
--- 507,517 ----
      }
  
      /**
!      * Gets the selected items on this scrolling list in an array of Objects.
!      * @return        an array of <code>Object</code>s representing the 
!      *                selected items on this scrolling list;
!      *                if no item is selected, a zero-length array is returned.
!      * @see #getSelectedItems
       * @see ItemSelectable
       */
      public Object[] getSelectedObjects() {

======================================================================
                                     
2004-06-11
EVALUATION

###@###.### 2003-05-20

Name: dkR10074			Date: 07/22/2003


A mistake was made in the java.awt.List class description of the doc
(see doc/api/java/awt/List.html).
Here is an excerpt from there:
---8<------------------------------------
For example, the code...

 List lst = new List(4, false);
 lst.add("Mercury");
 lst.add("Venus");
 lst.add("Earth");
 lst.add("JavaSoft");
 lst.add("Mars");
 lst.add("Jupiter");
 lst.add("Saturn");
 lst.add("Uranus");
 lst.add("Neptune");
 lst.add("Pluto");
 cnt.add(lst);

where cnt is a container, produces the following scrolling list: 

[an image]

Clicking on an item that isn't selected selects it. Clicking on
an item that is already selected deselects it.
In the preceding example, only one item from the scrolling list
can be selected at a time, since the second argument when
creating the new scrolling list is false. Selecting an item
causes any other selected item to be automatically deselected.
---8<------------------------------------

The sentences

  "Clicking on an item that isn't selected selects it.
   Clicking on an item that is already selected deselects it."

are true if a list is in a multiple-selection mode only. If a list
is in a single-selection mode, any click on list's item will
select a clicked item.
---

The Javadoc is changed to be more definite 
what happens if a java.awt.List component is in
a single-selection or a multiple-selection mode.
Please see suggested fix.
CCC decision, 2003/05/19

###@###.### 2003-07-22

======================================================================
                                     
2003-07-22



Hardware and Software, Engineered to Work Together