java.lang.ArrayIndexOutOfBoundsException: 0 >= 0 attempting to populate JTable

前端 未结 10 1607
猫巷女王i
猫巷女王i 2020-12-20 13:37

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          


        
10条回答
  •  春和景丽
    2020-12-20 14:38

    Dmitry is right, but you simply have to update your model. To do this, add the following to your code:

    DefaultTableModel dtm = (DefaultTableModel) table.getModel();
    for (int c = 0; c < table.getColumnCount(); c++) {
    dtm.addColumn(table.getColumnName(c));
    }
    

提交回复
热议问题