• Post Reply Bookmark Topic Watch Topic
  • New Topic

Refreshing data in a JTable  RSS feed

 
Chris Brandon
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Marshal
Posts: 55761
163
  • Mark post as helpful
  • send pies
  • 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.
 
Stevens Miller
Bartender
Posts: 1444
30
C++ Java Netbeans IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Stevens Miller. That solved my problem perfectly!
 
Stevens Miller
Bartender
Posts: 1444
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to help. Good luck with whatever you are doing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!