Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-09-2009, 04:04 PM
Member
 
Join Date: Jul 2009
Posts: 11
Rep Power: 0
IamKira is on a distinguished road
Default How to clone a JTable?
Hi,

I would like to create a ByVal copy of a JTable, however, the TableModel is not being cloned; I mean the clone and the original Table do have the same model and changing one changes the other too. Do I need to extend the DefaultTableModel and make it implement the CloneAble Interface as well? (And thus every object a JTable uses?) Or is there a nicer way to do this?

Thanks for help!
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 07-09-2009, 05:29 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 406
Rep Power: 3
tim is on a distinguished road
Default
Welcome IamKira, to Java Forums!

The DefaultTableModel represents it's data as references to objects. The Object class's clone method is protected. Also, it would be impractical to implement clone methods for every different class of every instance in the table's data model. The DefaultTableModel is represented by the JTable component using the toString() method. What I would do, is to instantiate a new DefaultTableModel object and populate it with the string representations of the objects in the original data modal. You can make this your clone() method for the DefaultTableModel extension if you like. However, all the objects will now be strings, but that's a quick solution.

Hope this helped.
__________________
Eyes dwelling into the past are blind to what lies in the future.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-09-2009, 05:46 PM
Member
 
Join Date: Jul 2009
Posts: 11
Rep Power: 0
IamKira is on a distinguished road
Default
Okay that should make it, I'm using only strings. thanks!
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-09-2009, 06:28 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 406
Rep Power: 3
tim is on a distinguished road
Default
Cool. It's a pleasure IamKira!
__________________
Eyes dwelling into the past are blind to what lies in the future.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with cast, equals and clone nellaf New To Java 1 04-19-2009 07:57 AM
How to clone an Array Java Tip java.lang 0 04-14-2008 09:46 PM
clone method javaplus New To Java 2 01-30-2008 10:47 AM
clone method gapper New To Java 1 01-20-2008 09:46 AM
clone problem feniger New To Java 13 01-13-2008 11:55 AM


All times are GMT +2. The time now is 05:53 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org