aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes update rows in jtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "update rows in jtable" Watch "update rows in jtable" New topic
Author

update rows in jtable

Aneresia White
Greenhorn

Joined: Dec 06, 2008
Posts: 12
I can update rows in database, but in jTable I see the changes only after I close the application and rerun it. What should I do?
This is my code:
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30929
    
158

Aneresia,
Welcome to JavaRanch!

I think this is more of a Swing question so I'll move it to our GUI forum.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

Where is your code to refresh the data?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Aneresia White
Greenhorn

Joined: Dec 06, 2008
Posts: 12
I tried this and I get the updated data , but the old rows are still there.
But after I rerun the application I get the correct data (the old one+the row updated).Hope you understand what I'm trying to say
So what should I do?
Mikko Kohtamäki
Ranch Hand

Joined: Dec 13, 2008
Posts: 112
looks a bit better, you forget to move fireTableRowsUpdated method in last line of you code/method ? And you have to include former rows too in fireTableRowsUpdated !
[ December 13, 2008: Message edited by: Mikko Kohtam�ki ]
Aneresia White
Greenhorn

Joined: Dec 06, 2008
Posts: 12
no that's not it. I'll show you my problem in pictures.
This is my table before update:
photobucket.com

This is my table after update:
photobucket.com

And what I want is now to add those rows again, just to update the table.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

Then don't just add them, but clear the model first: model.setRowCount(0).
Well, that's the simple way, that also handles insertions from outside your application. You could also find the row for each record and update it, but then you miss those inserts.
Aneresia White
Greenhorn

Joined: Dec 06, 2008
Posts: 12
oh great... thank you so much... it worked
That's what I didn't know, how to clear the model.
And now it seems so obvious. :roll:
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

shraddha sawant,
Your post was moved to a new topic.
Split from http://www.coderanch.com/t/416164/GUI/java/update-rows-jtable


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: update rows in jtable