United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4144295 : DefaultTableModel.moveRow(...) moves rows incorrectly.

Details
Type:
Bug
Submit Date:
1998-06-01
Status:
Resolved
Updated Date:
2000-02-24
Project Name:
JDK
Resolved Date:
2000-02-08
Component:
client-libs
OS:
solaris_2.5.1
Sub-Component:
javax.swing
CPU:
sparc
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.2.0
Fixed Versions:
1.4.0 (merlin)

Related Reports

Sub Tasks

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


                                     
2004-06-14
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
                                     
1999-11-22



Hardware and Software, Engineered to Work Together