Adding Columns to JTable dynamically

Posted by martilyo on Stack Overflow See other posts from Stack Overflow or by martilyo
Published on 2010-03-14T17:19:50Z Indexed on 2010/03/14 17:25 UTC
Read the original article Hit count: 481

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about java

Related posts about swing