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?
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?
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.
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.