[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] RFC: Make negative JList.setSelectedIndex() clear the selec
From: |
Mark Wielaard |
Subject: |
[cp-patches] RFC: Make negative JList.setSelectedIndex() clear the selection |
Date: |
Mon, 09 Jan 2006 16:43:20 +0100 |
Hi,
I have a program here that seems to expect JList.setSelectedIndex(-1) to
clear the current selection. Currently we get into trouble since we
unconditionally call setSelectionInterval(-1, -1) in that case. Changing
it to call clearSelection() when negative seems to make sense since it
is consistent with getSelectedIndex() which returns -1 when there is no
selection.
2006-01-09 Mark Wielaard <address@hidden>
* javax/swing/JList.java (setSelectedIndex): Clear selection when
argument is negative.
Does this patch make sense?
Cheers,
Mark
Index: javax/swing/JList.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JList.java,v
retrieving revision 1.44
diff -u -r1.44 JList.java
--- javax/swing/JList.java 3 Jan 2006 18:42:22 -0000 1.44
+++ javax/swing/JList.java 9 Jan 2006 15:43:27 -0000
@@ -1257,14 +1257,17 @@
*
* @param a A number in the half-open range <code>[0, x)</code> where
* <code>x = getModel.getSize()</code>, indicating the index of an
- * element in the list to select.
+ * element in the list to select. When < 0 the selection is cleared.
*
* @see #setSelectionMode
* @see #selectionModel
*/
public void setSelectedIndex(int a)
{
- selectionModel.setSelectionInterval(a, a);
+ if (a < 0)
+ selectionModel.clearSelection();
+ else
+ selectionModel.setSelectionInterval(a, a);
}
/**
signature.asc
Description: This is a digitally signed message part
- [cp-patches] RFC: Make negative JList.setSelectedIndex() clear the selection,
Mark Wielaard <=