• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help in updatin jtable

 
Abhi Chat
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

the problem is im gettin lettle messed up how to update the Jtables. I can load the data in the jtable for the first time. Now after search I need only to show the search records in the jtable..the fields remain the same....

any thought on this.....

Thanx

Abhi
 
Inuka Vincit
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you using an AbstracTableModel to store data for the JTable you need to
call fireTableDataChanged() inside AbstractTableModel(the extension ofcourse) or call the TableChanged method of the Jtable if your data in the table is stored some other way.
[ October 27, 2004: Message edited by: Inuka Vincit ]
 
mike acre
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Inuka Vincit:
... or call the TableChanged method of the Jtable if your data in the table is stored some other way.


No, this is called by the Swing code after a table change the only way you should use this is if you extend JTable and override it. Though this is definitely not a good approach.
 
Abhi Chat
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx guys for helpin me

Actually i have extented the AbstractTableModel and need to call fireTableDataChanged() to update the table...but my problem is

I have a inner class A which has the frame , tables(this is a nested class B inside A) and buttons. For the first time..the values get loaded to the table (setValue function) from a randomAccessfile from the constructor B called by A.

Now for each time the search button is clicked..I want to get values from the table (use getValue function)..search relevant information and then need to diaplay only the search result. But all this on button event which is in the class A. So how do i call the fireTabDataChanged...if i call it in the button even handler as .fireTabledatChanged..it doesnt work....

Any thought on this...
 
Richard Everhart
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Abhi Chat
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Rich,

thanx for the info....actually what i meant when i said im searchin the table is im searchin the object[][]..which i feel is easier to seach instead of the DB....the problem I had doubt..is that can i call firetablecahnged from a method in class A.[if u remember that the jtable is in class B which is an inner class of Class A] Is this the correct method to update or am i doin wrong?

Any thought on this...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic