File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes need help in updatin jtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "need help in updatin jtable " Watch "need help in updatin jtable " New topic
Author

need help in updatin jtable

Abhi Chat
Ranch Hand

Joined: Oct 10, 2004
Posts: 57
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


SCJP 1.4<br />Preparing for <br />SCJD and SCWCD
Inuka Vincit
Ranch Hand

Joined: Aug 10, 2004
Posts: 175
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 ]

MCP (C# application dev 70-316) 860<br />SCJP 1.4 100% SCJD (URLyBird) 378<br />MAD 100% nuts
mike acre
Ranch Hand

Joined: Sep 23, 2003
Posts: 197
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.


SCJP 1.4, SCJD
Abhi Chat
Ranch Hand

Joined: Oct 10, 2004
Posts: 57
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

Joined: Nov 19, 2003
Posts: 54
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

Joined: Oct 10, 2004
Posts: 57
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help in updatin jtable