Adding Columns to JTable dynamically
- by martilyo
I have an empty JTable, absolutely nothing in it. I need to dynamically generate its table columns in a certain way. A simplified version for the code I have for my attempt:
@Action
public void AddCol() {
for (int i = 0; i < 10; i++) {
TableColumn c = new TableColumn(i);
c.setHeaderValue(getColNam(i));
table.getColumnModel().addColumn(c);
}
}
But I'm getting an Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
error.
What am I doing wrong?