tags:

views:

29

answers:

2

I'm implementing a copy/paste example and when I set the clipboard like:

clipboard.setContents(new MyTransferable(image_label), null);

I want that image_label (is a JLabel) is a clone of the copied label

How can I do that?

A: 

JComponents don't override clone, but they are beans so you can use something like BeanUtils to copy the properties from a label to a new one.

Geoffrey Zheng
A: 

Since all Swing components are serializable, you can just serialize to memory/byte stream and deserialize back. This makes a good utility method for deep copying classes. If you want to speed it up a little bit, rewrite in/out streams to remove concurrency related code.

eugener