Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

howto: dispose of one and reload another JTable?  RSS feed

 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I've this requirement: when a user clicks on a JButton, select an item in a JComboBox etc, a different JTable will pop up in BoxLayout.CENTER to replace the default JTable.
For example, lets say you have a JTable of items, list prices, dates and warehouses for your city, but the user wants another one for another country, using another currency and discount pricing model. Its best to load another JTable, which looks different and has different formulae embedded in it.
You know, something like

but always clearing away the old JTable or the default one on the screen.
How does one clear away the default JTable and release whatever resources it might be holding on to ?
Just some workable ideas would be good.
THX :-)
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the first thing to do would be to get a hold of the contentpane holding your JTable. So your JPanel or whatever. You can issue a remove command, well...

Where panel is your contentpane, rootpane, JPanel. And someTable is your JTable.
Note that if your JTable is in a JScrollPane, you will remove the JScrollPane from the panel instead of the JTable.
Basically that is the gist of it. Any object that are specifically associated with the JTable, the GC should get rid of for you.
[ March 01, 2004: Message edited by: Gregg Bolinger ]
 
smitha verghese
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I dont understand y u need to dispose and it can b setVisible(false) or the object to b disposed set it as null.
hope u got me
smitha
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by smitha verghese:
Hi,
I dont understand y u need to dispose and it can b setVisible(false) or the object to b disposed set it as null.
hope u got me
smitha

Setting an objects visibility won't make it available to the GC. It's just invisible. If you need to get rid of an object, get rid of it. Also, just setting an object to null won't remove it from the Panel. And you will probably get runtime errors.
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your time and your input.
I think I'll go along with

that way, I'm confident GC with reclaim any resource it might be holding onto. Once a user has selected a new one, the user intends to work at it anyway.
Probably embedded in JScrollPane...
THX :-)
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!