-
CSR
-
Resolution: Approved
-
P4
-
None
-
behavioral
-
minimal
-
-
Java API
-
SE
Summary
Change method JList.setSelectedValue to clear selection when the object passed is null.
Problem
JList.setSelection method curretly calls JList.setSelectedIndex(-1) when the object passed is null. But calling setSelectedIndex(-1) does not serve any purpose. The expectation is that it should clear the selection when "null" is passed, as the function getSelectedValue returns "null" when nothing is selected. This makes these API's more compatible.
Solution
The change is to call clearSelection() instead of setSelectedIndex(-1) when the object passed is "null".
webrev: http://cr.openjdk.java.net/~pbansal/5076761/webrev.06/
Specification
The details of setSelectedValue of JList class which will be changed are as
src/java.desktop/share/classes/javax/swing/JList.java
/**
* Selects the specified object from the list.
* If the object passed is {@code null}, the selection is cleared.
*
* @param anObject the object to select
* @param shouldScroll {@code true} if the list should scroll to display
* the selected object, if one exists; otherwise {@code false}
*/
public void setSelectedValue(Object anObject,boolean shouldScroll) {}
- csr of
-
JDK-5076761 JList.setSelectedValue(null, ...) doesn't do anything
-
- Resolved
-