• Post Reply Bookmark Topic Watch Topic
  • New Topic

Refresh for JTable  RSS feed

 
bob morkos
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to populate a JTable on a button click? Need help.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have your own data model attached, you just reload the model and the JTable gets populated based on what is in the model.
 
bob morkos
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have any example or anywhere I can get info. I need to make my JTable populate from a click of a button. But as my application loads, my JTable has to be created and the data should be empty. After the user clicks a button "load" the JTable data gets populated and when a click another button "clear" the JTable data gets erased. I really need any help. Thanks.
Originally posted by Paul Stevens:
If you have your own data model attached, you just reload the model and the JTable gets populated based on what is in the model.

 
Steve Campbell
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several examples contained within the JDK. If you look under "demo\jfc\TableExample\src" at the .java files you should find what you need.
 
Mahajan Bhupendra
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Take a look at example by me..
http://www.javaranch.com/ubb/Forum2/HTML/003352.html

------------------
Bhupendra Mahajan
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
write 2 methods to remove & add new rows..
when u click on update then you remove the rows first & then add new rows, if you want to clear the table then just simply remove the rows..
the code for removing rows is as follows:
try
{
int count = model.getRowCount();
if (count!=0)
{
--count;
while(count>=0)
{
model.removeRow(count);
--count;
}
}
}
catch(Exception e)
{}
....
for adding:
model.addRow(..);
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinod, You might try this for the remove rows.

I assume you placed the try catch around it because of errors (ArrayIndexOutOfBound). You shouldn't get any errors with the above.
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow..something I didnt think about, thanx Paul!..yeah, ur assumption was right
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!