I\'m subclassing JTable and using a DefaultTableModel to model my table data. The following class sets up the JTable, and adds one row to the model.
import
From the JTable.setAutoCreateColumnsFromModel() API:
"This method calls createDefaultColumnsFromModel if autoCreateColumnsFromModel changes from false to true. "
Vector throws ArrayIndexOutOfBoundsException - if the index is out of range ( index < 0 || index >= size())
I guess the table model is missing the columns, as suggested by Dmitry
I think you need to add columns to your TableModel. Your code adds UI columns to the table but doesn't add them to the model
Replace your code with the following Here you need to remove first row only that should be iterated for all the rows
private void refreshTable() {
int rowCount= model.getRowCount();
// System.out.println(rowCount);
for(int i=0;i<rowCount;i++ ){
model.removeRow(0);
//System.out.println(i);
}
}
replace
tabWindow.addTab(...);
with
SwingUtilities.invokeLater(new Runnable() {
@Override public void run() {
tabWindow.addTab(...);
}
});
Such situation can hapen when you change tabbed pane in action listener.
It is necessary to add isCellEditable
method to your table model class with return false.
@Override
public boolean isCellEditable(int row, int column)
{
return false;
}
Dmitry is right. Replace
this.addColumn(ColumnName);
this.addColumn(ColumnSize);
this.addColumn(ColumnRmIcon);
with
Model.addColumn(ColumnName);
Model.addColumn(ColumnSize);
Model.addColumn(ColumnRmIcon);
and now the Model knows about the columsn and won't throw an Exception anymore when you try to add a row to a model which thinks it has 0 columns