Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Removing a jtable from a jpanel/Changing the table  RSS feed

 
Krit Christoforou
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey..
I've written this code, which creates a table with a scrollpane, and loads the results of a search, when a button is pressed.

The problem is that each time i press the button a new jtable is created. How can i make it either:
a) refill the same table
b) remove the table and make another one which displays the new results.
My code:




Thanks
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want the same table use a Table Model and modify/renew the data in it which will reflect in the JTable. If you want to reuse a JTable...

somePanel.remove(myScrollWithJTable);
somePanel.add(new MyScrollWithJTable);
somePanel.repaint();

Something like that anyway.
 
Krit Christoforou
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, i removed the table and created it again...
I couldnt figure out how to remove the table after the method ended since all my variables were valid in the {} they were declared.
So i did a panel[10].remove(panel[10].getComponent(0));
and it was ok
thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!