Adding rows to a JTable

后端 未结 3 1497
悲&欢浪女
悲&欢浪女 2020-12-03 01:46

We have a simple project where we read data from a socket and we want to populate a table with the coming data, but we can\'t find a way to add rows to a yet created J

3条回答
  •  悲&欢浪女
    2020-12-03 02:39

    If you use the default table model for a JTable then you can add rows with following code

     if ( dest+1 < table.getRowCount()-1 )
        ( (DefaultTableModel) table.getModel() ).insertRow(dest+1, getValuesForNewRow());
      else
        ( (DefaultTableModel) table.getModel() ).addRow(getValuesForNewRow());
    

提交回复
热议问题