Ask Your Question
4

How can the problem of JTable values getting replaced instead of being appended to the existing JTable be solved?

asked 2021-11-25 11:00:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-10-04 08:00:00 +0000

qstack gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-11-25 11:00:00 +0000

Seen: 12 times

Last updated: Oct 04 '21