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

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

    I was facing this problem because i was adding columns and rows to the JTable not to the model.

    best way is this.

    Object[][]rows = new Object[ ][ ] { {"a","b"} , {"c","d"} };
    Object[]columns = new Object[] {"column1","column2"};
    JTable table = new JTable();
    table.setModel(new DefaultTableModel(rows,columns));
    

提交回复
热议问题