Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

displaying data using tableModel

 
Lucy Sommerman
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following method in my AbstractTableModel class, and this is called from my GUI, to add rows to the table. Which is fine..the problem is, when the user hits the search button more than once, the new records to display are added to the end of the old records to display, whereas the desired behaviour is to clear the old rows from the table before adding new ones. Can somebody please advise the best way to clear the old rows from the table? Thanks very much.

public void recordsSearched(Vector rec) {
// Add record to underlying storage
rows.add(rec);
// refresh your view
fireTableRowsInserted(0, 0);
}
 
Omar Kalaldeh
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lucy,

You have to empty your "rows" collection first then add the search result, although I recommend you create a new instance of your rows collection and fill it with search results.
[ December 15, 2004: Message edited by: Omar Kalaldeh ]
 
James Clinton
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you create a TableModel from DefaultTableModel (which extends AbstractTableModel), I think a lot of this is handled for you. ( dont quote me ).

 
Lucy Sommerman
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks - I got it.

LS
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic