I doubt that support of null values in the data model is intentional
because JList is "A component that displays a list of *objects* and
allows the user to select one or more items."
The null behavior was not specified and work in most cases because some
of the getXXX methods in ListModel sub-classes and JList have a special
meaning of null:
JList.getSelectedValue(): Returns {@code null} if there is no selection.
ListModel.getElementAt(int index): In most cases implemented to return
null if index is incorrect.
Similar method TableModel.getValueAt(int,int) is also usually
implemented to return null if value is not found or some error occured.
JComboBox.setSelectedItem(): use <code>null</code> to clear the selection
ComboBoxModel.setSelectedItem(): <code>null</code> to clear the selection
ComboBoxModel.getSelectedItem(): <code>null</code> if there is no selection
So I suggest to follow initial intention here, because it is too late to
add validation of the values.
- The null value in get() will mean no-selection.
- The null value passed to set() will clear selection.
On 05/01/2018 02:15, Pankaj Bansal wrote:
Hi Semyon/Sergey,
Yes, JList can contain null elements as it can be added to data model. I think
this changes a lot in this bug. I think the selection needs to be cleared when
the object passed is not present in the list, irrespective of it being null or
not. I have made code changes. Please have a look.
Webrev: http://cr.openjdk.java.net/~pbansal/5076761/webrev.02/
Regards,
Pankaj Bansal
-----Original Message-----
From: Semyon Sadetsky
Sent: Friday, January 5, 2018 6:59 AM
To: Pankaj Bansal; swing-dev@openjdk.java.net
Subject: Re: <Swing Dev> [11] Review Request: JDK-5076761 :
JList.setSelectedValue(null, ...) doesn't do anything
Hi Pankaj,
Can JList contain null value?
--Semyon
On 01/02/2018 11:26 PM, Pankaj Bansal wrote:
Hi Sergey,
Thanks for the review.
I have made the suggested changes. Please have a look.
webrev: http://cr.openjdk.java.net/~pbansal/5076761/webrev.01/
Regards,
Pankaj Bansal
-----Original Message-----
From: Sergey Bylokhov
Sent: Wednesday, January 3, 2018 3:31 AM
To: Pankaj Bansal; swing-dev@openjdk.java.net; Prasanta Sadhukhan
Subject: Re: [11] Review Request: JDK-5076761 :
JList.setSelectedValue(null, ...) doesn't do anything
Hi, Pankaj.
The fix looks fine, but I suggest to update the spec as well and describe the behavior if
"null" value is passed.
On 02/01/2018 02:07, Pankaj Bansal wrote:
Hi All,
Please review the fix for JDK 11.
Bug:
https://bugs.openjdk.java.net/browse/JDK-5076761
Webrev:
http://cr.openjdk.java.net/~pbansal/5076761/webrev.00/
Issue:
When setSelectedValue is called on JList with null object, it should
clear all selection. But it is not doing anything.
Fix:
In setSelectedValue if the object is null, the setSelectedIndex is
called with -1. but this does not clear the selection. We should be
calling clearSelection instead of SetSelectedIndex.
Regards,
Pankaj Bansal
--
Best regards, Sergey.
--
Best regards, Sergey.