• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Refreshing data in a JTable

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

I am quite new to Java and have been trying to learn a bit about JTables for a project I want to undertake. I have created a new JFrame in netbeans and added a button. Onclicking the button I want add some data to a JTable model and then output the JTable with the data. When I click the button again I want the same process to happen again and overwrite the previous table being displayed.

I have written the following code below:



The problem I have is that when I click the button for a second time the table stays on the screen exactly as it did following the first click. I can see that the data in the model is changing so I am not sure why a new JTable is not drawn. Can anyone shed any light on where I am going wrong?

Thanks.

Chris.
 
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I know precious little about JTables myself, but have you checked the Java Tutorials? I don't know whether the parts about data listeners and change listeners will help you.

We usually discuss tables in the GUIs forum; I shall move you there.
 
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks to me like each button click is creating a new default table model at Line 59, and installing it into the table at Line 110. That's always going to result in the code from Lines 91 through 102 being run once for each new table you create upon each click of the button, with the end result being you are getting an identical (albeit new) table each time.
 
Chris Brandon
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Stevens Miller. That solved my problem perfectly!
 
Stevens Miller
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to help. Good luck with whatever you are doing.
 
Liar, liar, pants on fire! refreshing plug:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic