Re: Help Cloning Objects



Bill schrieb:
Hi All,
I currently have a database 'explorer' application - show lists of
tables; ddl etc etc

I'd now like to be able to 'clone' a snapshot view into another
frame....

frame 1
has a jpanel_X + scroll pane + jtable with data etc

new frame 2
has a jpanel_Y - which I'd like to reflect the exact same contents as
frame 1

I've tried
panel_Y = panel_X.clone();
but get
Error(35,26): method clone() has protected access in class
java.lang.Object

I've added the Cloneable interface to jpanel_X - but I still get the
error message....

TIA

Bill


Hi Bill

What you would like to have is a clone of the data, not a clone of the
panel.
So you should clone the data in the table by either cloning the (your)
TableModels or the data contained in it.

First you have to make your class implement the Cloneable Interface and
implement the clone method as public. This is what the error message says...

Hope that helps
Dieter
.



Relevant Pages

  • Help Cloning Objects
    ... I'd now like to be able to 'clone' a snapshot view into another ... new frame 2 ... public class V_Db2Explorer_ListView extends JPanel ...
    (comp.lang.java.gui)
  • Re: cloning an Observable
    ... > object was copied from the original into the clone. ... I have a class that draws a complex view onto a frame, ... modify a couple of settings in it. ... // dummy observer class. ...
    (comp.lang.java.programmer)
  • Re: Dooku could not have ordered the clone army
    ... The Clone has growth accelerator which double the growth of a normal ... Doesn't the time frame seem off, in light of the age of the ... Wouldn't it have had to be Maul or someone else? ...
    (alt.fan.starwars)
  • How to clone a Swing JFrame?
    ... I tried with the function clone() but without success; ... "original" frame: the events tied to the listeners are ignored; ... objects are physically cloned but their listeners are not cloned. ...
    (comp.lang.java.gui)
  • Re: Why not cloneable by default?
    ... Some classes' nature is simply inconsistent with cloning ... > I want to preserve a state snapshot then the shallow clone provided by ... have control over whether their instances can be cloned. ... Cloneable interface could still have contained a public clonemethod, ...
    (comp.lang.java.programmer)