Results 1 to 4 of 4
Thread: How to clone a JTable?
- 07-09-2009, 03:04 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 11
- Rep Power
- 0
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!
- 07-09-2009, 04:29 PM #2
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. :D
Hope this helped. :pEyes dwelling into the past are blind to what lies in the future. Step carefully.
- 07-09-2009, 04:46 PM #3
Member
- Join Date
- Jul 2009
- Posts
- 11
- Rep Power
- 0
Okay that should make it, I'm using only strings. thanks!
- 07-09-2009, 05:28 PM #4
Similar Threads
-
Help with cast, equals and clone
By nellaf in forum New To JavaReplies: 1Last Post: 04-19-2009, 06:57 AM -
How to clone an Array
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:46 PM -
clone method
By javaplus in forum New To JavaReplies: 2Last Post: 01-30-2008, 09:47 AM -
clone method
By gapper in forum New To JavaReplies: 1Last Post: 01-20-2008, 08:46 AM -
clone problem
By feniger in forum New To JavaReplies: 13Last Post: 01-13-2008, 10:55 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks