Before this problem did not arise, I do not understand what to do. Initially, the table has only headers, but after adding a record, only an empty table remains.


public NewJFrame() { initComponents(); DefaultTableModel d = new DefaultTableModel(); d.addRow(new Object[] {1, 2}); jTable1.setModel(d); } 

    1 answer 1


     DefaultTableModel d = new DefaultTableModel(0 /*rowCount*/, 2 /*columnCount*/); 

    so or

     DefaultTableModel d = new DefaultTableModel(); d.addColumn("First row head"); d.addColumn("Second row head"); 
    • And what exactly does this code do? More precisely, what are the parameters in brackets? - Sergey1991
    • @ Sergey1991: there are even comments there :) the number of rows and columns. - VladD
    • @ Sergey1991: here should be useful:… - VladD
    • Well, I already have headers, why add them again? - Sergey1991
    • @ Sergey1991: well, so do not add, if not necessary. ;-) I didn't see them in your code, so I wrote them. Use the first option if there are headers. - VladD