Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One solution is to use a table model that dynamically updates the JTable as new values are added. This can be accomplished by creating a custom table model class that extends the DefaultTableModel class and overrides the getValueAt(), getColumnCount(), getRowCount(), setValueAt(), and isCellEditable() methods.

In the setValueAt() method, the new value is added to the existing data in the table model rather than replacing it. Then, the table model fires a table changed event to notify the JTable that the data has been updated.

Another solution is to keep track of the existing data in a separate ArrayList or array and append new values to it before updating the JTable. This can be done by implementing an event listener that listens for changes to the data and updates the JTable accordingly.

It is also important to ensure that the JTable is using the correct table model and that the data being added is in the correct format and matches the columns of the JTable.