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:
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 ]
Joined: Feb 28, 2001
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!
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 ]