英文:
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);
英文:
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论