• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable will not clear

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic