Right after you add a row or delete it, revalidate the table.
table.revalidate();
call that on the table, NOT the table model.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
Also, is it really necessary that you use the abstract table model? I'm using default right now and it's much easier to use. It simply has a method called addRow() and addColumn() that would probably suit your needs and make life easier on you.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
I did this just the other day! I would suggest using the DefaultTableModel, you'll have an easier time with it.
This was my code:
int c = dtm.getRowCount();
for (int i=c-1; i>=0; i--)
{
dtm.removeRow(i);
mortgageTable.revalidate();
}
dtm is a DefaultTableModel
mortgageTable is the JTable
Compare your code with mine. It will be somewhat different, but overall it should look similar. Again, I really think you should use the DefaultTableModel instead.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
Swing is a single-threaded event model. If you are executing the code that updates the table in a button action listener then you are essentially "holding-up" processing other UI events like repaints, table updates, etc.
If you want the table to update over the course of a long running process you will need to perform that processing in a separate thread and push UI updates onto the event dispatch thread.
This tutorial may help: http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847