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

Denise Advincula

Ranch Hand

Posts: 163

posted 9 years ago

I have an empty JTable displayed on the first loading of the JFrame. Upon click of the Search Button, the JTableshould 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.

SCJP/OCPJP 6 | SCWCD/OCPJWCD 5 | OCMJEA in progress...

pete stein

Bartender

Posts: 1561

posted 9 years ago

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

posted 9 years ago

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!