File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes displaying data using tableModel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "displaying data using tableModel" Watch "displaying data using tableModel" New topic

displaying data using tableModel

Lucy Sommerman
Ranch Hand

Joined: Nov 25, 2004
Posts: 61
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
// refresh your view
fireTableRowsInserted(0, 0);
Omar Kalaldeh
Ranch Hand

Joined: Jun 08, 2004
Posts: 58
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 ]

Best Regards <br /> <br />Omar F. Kalaldah<br />---------------------<br />SCJP, SCJD, SCBCD
James Clinton
Ranch Hand

Joined: Jun 23, 2003
Posts: 190
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

Joined: Nov 25, 2004
Posts: 61
Ok thanks - I got it.

I agree. Here's the link:
subject: displaying data using tableModel
It's not a secret anymore!