This week's book giveaways are in the AI and JavaScript forums.
We're giving away four copies each of GANs in Action and WebAssembly in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

update rows in jtable

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
author & internet detective
Posts: 39789
797
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aneresia,
Welcome to JavaRanch!

I think this is more of a Swing question so I'll move it to our GUI forum.
 
Sheriff
Posts: 21842
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your code to refresh the data?
 
Aneresia White
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21842
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shraddha sawant,
Your post was moved to a new topic.
Split from https://coderanch.com/t/416164/GUI/java/update-rows-jtable
 
it's a teeny, tiny, wafer thin ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!