-
Bug
-
Resolution: Fixed
-
P4
-
1.2.2, 1.4.2, 11
-
b04
-
generic, x86
-
generic, windows_2000
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)
======================================================================
- csr for
-
JDK-8196569 JList.setSelectedValue(null, ...) doesn't do anything
-
- Closed
-
- duplicates
-
JDK-8198281 [TESTBUG] javax/swing/JList/SetSelectedValueTest.java
-
- Closed
-