posted 20 years ago
Hi Abhi,
I hope I can give you a hand here, Abhi, by telling you a bit about how I use JTable for my solution.
First, I don't use AbstractTableModel because DefaultTableModel does everything I need, so much so that the inner class I used as my TableModel is only about 20 lines long, including comments. In DefaultTableModel whenever you add a row using either addRow(Object[]) or addRow(Vector), or remove a row with removeRow(int), the method you're asking about, fireTableDataChanged(), is called, updating the table for you. In the case of displaying seach results, I first clear the table. If I don't do this then the table will end up displaying the search results in addition to all the other records displayed in the table. I wish DefaultTableModel had some sort of 'clear table' method but it doesn't - I had to write that myself, but it's pretty simple. Here's a snippet for you:
As for how you are displaying your search results you mention that when you press the search button, causing fileTableDataChanged() to be called, nothing happens in your table. I'm wondering if you've manipulated the table so that the search results will be displayed? If you haven't then fireTableDataChanged() won't do anything... I think :-).
Also, as for your design, do you really want to search your table for matching records? I would think you would want to search the database, using the results from there to add to your display.
Rich
[ October 28, 2004: Message edited by: Richard Everhart ]