克隆 Swing 组件 [英] Cloning a Swing component

查看:39
本文介绍了克隆 Swing 组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个复制/粘贴示例,当我将剪贴板设置为:

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

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

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

我希望 image_label(是一个 JLabel)是复制标签的克隆

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

我该怎么做?

推荐答案

由于所有 Swing 组件都是可序列化的,因此您只需将其序列化为内存/字节流并反序列化即可.这为深度复制类提供了一个很好的实用方法.如果您想稍微加快速度,请重写输入/输出流以删除与并发相关的代码.

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.

这篇关于克隆 Swing 组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆