多个对象复制到剪贴板

huangapple go评论75阅读模式
英文:

Multiple objects to clipboard

问题

我的问题是,我想要复制一些文本一张图片到系统剪贴板。我尝试过使用awt和javafx,但没有找到方法来实现。

我尝试过使用awt的方法来处理单个图片。不确定如何添加多个内容。

MyTransferableImage image = new MyTransferableImage();
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(image, this);

以及javafx的方法:

Clipboard clipboard = Clipboard.getSystemClipboard();
ClipboardContent content = new ClipboardContent();
content.putImage(myImage);
// 编辑
clipboard.setContent(content);

但是都无法在剪贴板上存储多个元素。

英文:

My problem is that I would like to copy some text and an image to the system's clipboard. I have tried with awt, and javafx but have not found the way to do it.

I've tried the awt solution for a single image. Not sure how to add multiple content.

MyTransferableImage image = new MyTransferableImage();
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(image, this);

and the javafx solution:

Clipboard clipboard = Clipboard.getSystemClipboard();
ClipboardContent content = new ClipboardContent();
content.putImage(myImage);
// edited
clipboard.setContent(content);

But neither was able to store multiple elements on clipboard.

答案1

得分: 3

你没有将创建的内容设置到ClipBoard

final Clipboard clipboard = Clipboard.getSystemClipboard();
final ClipboardContent content = new ClipboardContent();

// 添加你的元素
content.putString("文本");
content.putImage(new Image("https://www.oracle.com/a/tech/img/cb88-java-logo-001.jpg"));

// 设置剪贴板的内容
clipboard.setContent(content);

参考:Clipboard : Oracle 帮助中心

英文:

You are not setting the created content to the ClipBoard :

final Clipboard clipboard = Clipboard.getSystemClipboard();
final ClipboardContent content = new ClipboardContent();

// Add your elements
content.putString("Text");
content.putImage(new Image("https://www.oracle.com/a/tech/img/cb88-java-logo-001.jpg"));

// Set the Clipboard's content
clipboard.setContent(content);

ref: Clipboard : Oracle Help Center

huangapple
  • 本文由 发表于 2020年3月16日 17:33:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/60703412.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定