• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to load JTable's values in a JButton's actionPerformed event  RSS feed

 
Denise Advincula
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an empty JTable displayed on the first loading of the JFrame. Upon click of the Search Button, the JTable should be filled with values.
I'm not sure how to do it. I'm confused if I still have to get a JTable reference and then set it. I tried that but I wasn't successful.
I'm lost on the code below (the bold lines). I hope somebody can help me. Thank you.

 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what you want is a JTable that is modifiable by your code. I'm no expert in this, but it sounds to me like you should look into using a DefaultTableModel object and then setup your table to use this model. This can easily be done through the JTable's constructor. Then when you need to update the table, insert the information into the model via the methods that it has available for this (check the API but I think that you'll likely use addRow(...) ), and your table should then reflect the changes made to the model.

Good luck!
[ August 10, 2008: Message edited by: pete stein ]
 
Denise Advincula
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the idea! I used the DefaultTableModel. Upon click of the search button I can now populate the table using the methods in the API. Now it's OK. Thanks!
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool! Glad it helped.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!