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 JTable object, we can only find how to add rows at creation time of the table.
Is it possible to add rows dynamically to a JTable, or there is a better alternative object to deal with this way of showing data?
EDIT: Thanks a lot for your answers.
All three of them look very promising, but I have to choose only one and I think the best is Guillaume’s.
You should create a custom
TableModel. AJTabledoesn’t actually store the rows, it always delegates that to aTableModel. To help you implementing it, you should make use ofAbstractTableModel. Don’t forget to callfireTableRowsInserted()every time you add rows. For better performances if you add a lot of rows, try to batch the updates and add many rows at a time.