java从JavaFX应用程序复制图像并使用Windows粘贴
我正在开发一个JavaFX应用程序。我想从应用程序复制图像使用上下文菜单和粘贴它使用Windows的粘贴功能
File file = new File("C:\\Users\\Admin\\Desktop\\my\\mysql.gif");
Image image = new Image(file.toURI().toString());
ImageView ive =new ImageView(image);
cm = new ContextMenu();
MenuItem copy = new MenuItem("Copy");
cm.getItems().add(copy);
copy.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent t) {
//Paste Image at location
Clipboard clipboard = Clipboard.getSystemClipboard();
ClipboardContent content = new ClipboardContent();
content.putImage(image); // the image you want, as javafx.scene.image.Image
clipboard.setContent(content);
}
});
例如,如下图所示
并希望在使用Windows功能菜单的位置粘贴
# 1 楼答案
使用^{} 和^{} ,例如:
要使Windows上下文菜单的“粘贴”操作正常工作,剪贴板内容必须是
File
。在上面演示的例子中,这很容易,否则应该创建一个临时文件