Trying to select the multiple rows with arrow keys indicates that the DefaultListSelectionModel is not firing correct events to repaint the changed area. This path fixes that problem.

2006-03-31  Audrius Meskauskas  <[EMAIL PROTECTED]>

   * javax/swing/JTable.java (columnSelectionChanged):
   Removed print statement.
   * javax/swing/DefaultListSelectionModel.java
   (addSelectionInterval, removeSelectionInterval):
   Fire the difference between selection. (setLeadSelectionIndex):
   Fire the difference and mark current and previous lead
   selection indexes for repaint.

Index: DefaultListSelectionModel.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/DefaultListSelectionModel.java,v
retrieving revision 1.27
diff -u -r1.27 DefaultListSelectionModel.java
--- DefaultListSelectionModel.java	31 Mar 2006 10:13:15 -0000	1.27
+++ DefaultListSelectionModel.java	31 Mar 2006 21:39:21 -0000
@@ -286,8 +286,14 @@
     int beg = sel.nextSetBit(0), end = -1;
     for(int i=beg; i >= 0; i=sel.nextSetBit(i+1)) 
       end = i;
-    if (sel.equals(oldSel) == false)
-      fireValueChanged(beg, end, valueIsAdjusting);    
+    
+    BitSet old = (BitSet) oldSel;
+    
+    // The new and previous lead location requires repainting.
+    old.set(oldLeadIndex, !sel.get(oldLeadIndex));
+    old.set(leadSelectionIndex, !sel.get(leadSelectionIndex));
+    
+    fireDifference(sel, old);
   }
 
   /**
@@ -492,8 +498,7 @@
         leadSelectionIndex = index1;
         anchorSelectionIndex = index0;
         sel.set(lo, hi+1);
-        if (sel.equals(oldSel) == false)
-          fireValueChanged(lo, hi, valueIsAdjusting);
+        fireDifference(sel, (BitSet) oldSel);
       }
   }
 
@@ -530,8 +535,8 @@
     //TODO: will probably need MouseDragged to test properly and know if this works
     setAnchorSelectionIndex(index0);
     leadSelectionIndex = index1;
-    if (sel.equals(oldSel) == false)
-      fireValueChanged(lo, hi, valueIsAdjusting);
+    
+    fireDifference(sel, (BitSet) oldSel);
   }
 
   /**
Index: JTable.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/JTable.java,v
retrieving revision 1.93
diff -u -r1.93 JTable.java
--- JTable.java	31 Mar 2006 21:10:08 -0000	1.93
+++ JTable.java	31 Mar 2006 21:39:29 -0000
@@ -1886,7 +1886,6 @@
     
     int idx0 = event.getFirstIndex();
     int idxn = event.getLastIndex();
-    System.out.println("IDX "+idx0+"-"+idxn);
     int i;
 
     for (i = 0; i < idx0; i++)
Index: plaf/basic/BasicTableUI.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/plaf/basic/BasicTableUI.java,v
retrieving revision 1.48
diff -u -r1.48 BasicTableUI.java
--- plaf/basic/BasicTableUI.java	31 Mar 2006 10:13:16 -0000	1.48
+++ plaf/basic/BasicTableUI.java	31 Mar 2006 21:39:34 -0000
@@ -1250,6 +1250,8 @@
         widths[i] = cmodel.getColumn(i).getWidth();
       }
     
+    System.out.println(r0+":"+c0+"-"+rn+":"+cn);
+    
     Rectangle bounds = table.getCellRect(r0, c0, false);
     bounds.height = table.getRowHeight()+table.getRowMargin();
     

Reply via email to