wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JTable will not clear Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable will not clear" Watch "JTable will not clear" New topic
Author

JTable will not clear

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
I have a table that is populated with data if a record is found in the DB. When a record isn't found, an exception is thrown. After displaying the exception, I want to clear the data from the table, if any.

Here is how I have my table set up:
bim = new BOMInquiryModel();
sorter = new TableSorter(bim);
cs = new CellSpan1();
table = new CSTable(cs,sorter);
- BOMInquiryModel extends DefaultTableModel
-TableSorter extends TableMap which extends AbstractTableModel.
-CellSpan1 implements an interface to span columns
-CSTable takes a CellSpan object, and a TableModel.
I have tried setting the number of rows to zero after the exception occurs, and then repainting the table as well as calling the fireTableDataChanged method, but that did not work. This is the code I've tried:

This is the code I tried:


What am I missing here?
Thanks in advance!
Abhik Sarkar
Ranch Hand

Joined: Jun 14, 2003
Posts: 61
Hi Jennifer,
I am not sure if I am correct or not, but from what you have told us, this is what I can guess...
Your table is created from the TableSorter model which extends AbstractTableModel, and not DefaultFaultTable.
However, when you catch the exception, you are casting the table's model to a DefaultTableModel. I am not sure if you would get the expected behaviour.
I would try one of the following:

Or, I would create a method in the TableSorter, say called, empty(), which would empty out the BOMInquiryModel and call fireTableDataChanged internally.
Hope this helps,
Abhik.
[ July 18, 2003: Message edited by: Abhik Sarkar ]
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Thanks for the reply. I tried the suggestion you gave me and it did not work. However, after more tinkering around with it, I found that removing all the elements from the Vector in my model works wonderfully.
Thanks for your help!
VIJAY Yadlapati
Ranch Hand

Joined: Aug 04, 2003
Posts: 175
TableModel (and its subclasses) holds the data of JTable. Any thing you have to deal with data, you should use TableModel only.
As you are using DefaultTableModel, use setDataVector(null, columnHeaders) on DefaultTableModel.
Another way is to set null TableModel to JTable itself.
[ August 12, 2003: Message edited by: VIJAY Yadlapati ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable will not clear
 
Similar Threads
get changed values from JTable
tablesorter problem
refresh problem
How to organize the client interface for adding new data into database?
Removing rows from DefaultTableModel