-
Bug
-
Resolution: Fixed
-
P3
-
1.3.0
-
merlin
-
sparc
-
solaris_2.6
Name: aaC67449 Date: 09/01/99
table.DefaultTableModel.setDataVector(newData, columnNames) doesn`t adjust rows to match the number of columns (setted by size of columnNames vector).
See example.
javadoc says:"
public void setDataVector(Vector newData,
Vector columnNames)
This replaces the current dataVector instance variable with the new Vector of rows,
newData. columnNames are the names of the new columns. The first name in columnNames is
mapped to column 0 in newData. Each row in newData is adjusted to match the number of
columns in columnNames either by truncating the Vector if it is too long, or adding null
values if it is too short.
Parameters:
newData - The new data vector
columnNames - The names of the columns
See Also:
newDataAvailable(javax.swing.event.TableModelEvent), getDataVector()
"
See example.
------------- example --------------
import javax.swing.table.DefaultTableModel;
import java.util.Vector;
public class Test{
public static void main(String argv[]) {
DefaultTableModel c = new DefaultTableModel();
// create column names vector for 10 columns
Vector idTest = new Vector();
for (int j = 0; j < 10; j++) {
idTest.addElement(new Object());
}
// create data vector whith 5 columns
Vector testVector = new Vector();
for (int i = 0; i < 5; i++) {
Vector elem = new Vector();
for (int j = 0; j < 5; j++) {
elem.addElement(new Object());
}
testVector.addElement(elem);
}
// set new data vector
c.setDataVector(testVector, idTest);
System.out.println("ColumnCount="+c.getColumnCount());
// try to get an added null value
if(c.getValueAt(4, 7)==null) {
System.out.println("Failed");
} else {
System.out.println("Passed");
}
}
}
------------- output ---------------
ColumnCount=10
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7 >= 5
at java.util.Vector.elementAt(Vector.java:409)
at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:629)
at Test.main(Test.java:28)
======================================================================