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

前端 未结 10 1636
猫巷女王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:35

    Another issue might be related when you use RowSorter. When you edit the model RowSorter tries to re-sort the old model. It should be automatically re-created and re-run on each changes of table model.

    You can fix it by

    tableModel = new DefaultTableModel(data, columnNames);
    jTableSentence.setModel(tableModel);
    jTableSentence.setRowSorter(new TableRowSorter(tableModel));
    jTableSentence.setAutoCreateRowSorter(true);
    

    -Hayri

提交回复
热议问题