JDK-4144295 : DefaultTableModel.moveRow(...) moves rows incorrectly.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_2.5.1
  • CPU: sparc
  • Submitted: 1998-06-01
  • Updated: 2000-02-24
  • Resolved: 2000-02-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 merlinFixed
Description

Name: aaC67449			Date: 06/01/98



DefaultTableModel.moveRow(...) moves rows incorrectly.

javadoc says:"
public void moveRow(int startIndex,
                    int endIndex,
                    int toIndex)

    Moves one or more rows starting at startIndex to endIndex in the model to the toIndex. This method will send a
    tableChanged() notification message to all the listeners. 

    Examples of moves:

    1. moveRow(1,3,5);   

    a|B|C|D|e|f|g|h|i|j|k - before a|e|f|B|C|D|g|h|i|j|k - after 
    
    2. moveRow(6,7,1);

    a|b|c|d|e|f|G|H|i|j|k - before a|G|H|b|c|d|e|f|i|j|k - after
    Parameters:
        startIndex - the starting row index to be moved
        endIndex - the ending row index to be moved
        toIndex - the destination of the rows to be moved
    Throws:
        ArrayIndexOutOfBoundsException - if any of the indices are out of range. Or if endIndex is less than
        startIndex.
"

The following example represent the first example from javadoc, and its results are different from javadoc ones.     


------------------Example-----------------------------------

import java.awt.swing.table.*;
import java.util.*;

public class Test {

   public static void main(String argv[]) {

    int  results[]={0,4,5,1,2,3,6,7,8,9};
    
    Vector elem=null;
    DefaultTableModel c = new DefaultTableModel(0,1); 
        
// create table {0,1,2, ... }

    for(int k=0;k<10;k++) {
         elem=new Vector();  
         elem.addElement(new Integer(k));
         c.addRow(elem);   // add row
    }
      
    c.moveRow(1,3,5);  // move rows
    
    for(int k=0;k<5;k++)
      if(!(new Integer(results[k])).equals(c.getValueAt(k,0))){ 
           System.out.println("Method works incorrectly:"+c.getDataVector());
           System.out.println("Should be: {0,4,5,1,2,3,6,7,8,9}");
           break;
      }
  }  

}

-------------------Output------------------------------------
Method works incorrectly:[[0], [2], [4], [1], [3], [5], [6], [7], [8], [9]]
Should be: {0,4,5,1,2,3,6,7,8,9}

======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic merlin FIXED IN: merlin merlin-beta INTEGRATED IN: merlin merlin-beta
14-06-2004

EVALUATION I've verified the output of the sample. It appears to not move the range specified. If this is intended behavior then the docs need updating. Otherwise the model needs fixing. steve.wilson@eng 1998-06-01 This is a bug that I verified. This is broken because of the way we index when making the moves. Simple fix can be seen in the Suggeted Fix area of this bug report. Loop moves based on how many rows are going to move. gary.collins@East 1999-11-22 Fix applied to new Merlin workspace, thanks. philip.milne@eng 2000-02-08
22-11-1999