How to clone a JTable?
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!
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. :p
Okay that should make it, I'm using only strings. thanks!
Cool. It's a pleasure IamKira! :D