Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Jtable - TableModel Problem while setting rowcount

794822Jun 21 2010 — edited Jun 21 2010
I have a TableModel which extends from defaulttablemodel

I have a method to set new rows size.
First to call setRowCount I re-create the 'data' Object, that initially has 5 x 5 elements

If I call my function wiht 8 x 5, I get the next fail :

java.lang.ArrayIndexOutOfBoundsException: 5 >= 5
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableModel.justifyRows(Unknown Source)
at javax.swing.table.DefaultTableModel.setNumRows(Unknown Source)
at javax.swing.table.DefaultTableModel.setRowCount(Unknown Source)
at geocost.Wtable.w_setrows(Wtable.java:66)


The code is something like this :
public void w_setrows(int rows, int cols) {
TableModelo.w_Gen_Object(rows,cols);
TableModelo.setRowCount(rows); ( this is the line 66 )
}
.....
private void w_Gen_Object(int numRows,int numCols){
data = new Object[numRows][numCols];
for (int i=0; i < numRows; i++) {
for (int j=0; j < numCols; j++) {
data[i][j]="";
}
}
}
Whats wrong ?
Thank you
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 19 2010
Added on Jun 21 2010
4 comments
651 views