Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从javafx应用程序复制图像,并使用窗口功能粘贴它_Java_Javafx_Javafx 2_Fxml_Javafx 8 - Fatal编程技术网

从javafx应用程序复制图像,并使用窗口功能粘贴它

从javafx应用程序复制图像,并使用窗口功能粘贴它,java,javafx,javafx-2,fxml,javafx-8,Java,Javafx,Javafx 2,Fxml,Javafx 8,我正在开发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(); MenuIt

我正在开发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);
        }
    });
File File=new文件(“C:\\Users\\Admin\\Desktop\\my\\mysql.gif”);
Image Image=新图像(file.toURI().toString());
ImageView ive=新的ImageView(图像);
cm=新上下文菜单();
MenuItem copy=新MenuItem(“副本”);
cm.getItems().add(复制);
copy.setOnAction(新的EventHandler(){
@凌驾
公共无效句柄(ActionEvent t){
//在指定位置粘贴图像
剪贴板=剪贴板。getSystemClipboard();
ClipboardContent=新的ClipboardContent();
content.putImage(image);//所需的图像,如javafx.scene.image.image
剪贴板。设置内容(content);
}
});
例如,如下图所示

并希望使用“窗口功能”菜单粘贴到位置

使用和,例如:

Clipboard clipboard = Clipboard.getSystemClipboard();
ClipboardContent content = new ClipboardContent();
// for paste as image, e.g. in GIMP
content.putImage(image); // the image you want, as javafx.scene.image.Image
// for paste as file, e.g. in Windows Explorer
content.putFiles(java.util.Collections.singletonList(new File("C:\\Users\\Admin\\Desktop\\my\\mysql.gif")));
clipboard.setContent(content);

要使Windows上下文菜单的“粘贴”操作生效,剪贴板内容必须是
文件
。在上面演示的例子中,这很容易,否则应该创建一个临时文件。

我尝试过,但不起作用。我被编辑成上述问题。检查一下。粘贴选项不可用对于这种情况,您只需将文件放入剪贴板,请参见编辑。这适用于Gimp和Paint,但在Microsoft Word中不起作用。。你有什么想法吗?但是它适用于Microsoft Powerpoint..也许可以尝试
ClipboardContent.putImage()
方法?