This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

displaying data using tableModel

 
Lucy Sommerman
Ranch Hand
Posts: 61
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks - I got it.

LS
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic