我具有以下代码,旨在将JavaFX应用程序中的一系列文件放入系统剪贴板中:
pane.setOnDragDetected(event -> {
List<File> files = ...
Dragboard dragBoard = ((Node)event.getsource()).startDragAndDrop(TransferMode.COPY);
ClipboardContent clipboardContent = new ClipboardContent();
clipboardContent.putFiles(files);
dragBoard.setContent(clipboardContent);
event.consume();
});
该代码在Java 11(Oracle JDK 11.0.1)上运行良好。
在Java 13(OpenJDK 13.0.1)上,但是如果我将多个文件放入剪贴板(其中一个也可以很好地工作)并显示以下错误消息,则此操作将失败:
2019-11-09 23:53:28.956 java[50078:1146885] *** Terminating app due to uncaught exception 'NSGenericException',reason: 'There are 3 items on the pasteboard,but 1 drag images. There must be 1 draggingItem per pasteboardItem.'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff2db3af53 __exceptionPreprocess + 250
1 libobjc.A.dylib 0x00007fff63c00835 objc_exception_throw + 48
2 CoreFoundation 0x00007fff2db3ada9 +[NSException raise:format:] + 189
3 AppKit 0x00007fff2afc93bb -[NSDraggingSession(NSInternal) _initWithPasteboard:image:offset:source:] + 247
4 AppKit 0x00007fff2afc8dee -[NSCoreDragManager dragImage:fromWindow:at:offset:event:pasteboard:source:slideBack:] + 1889
5 AppKit 0x00007fff2afc867d -[NSWindow(NSDrag) dragImage:at:offset:event:pasteboard:source:slideBack:] + 134
6 libglass.dylib 0x000000012f55a618 -[GlassViewDelegate startDrag:] + 1080
7 libglass.dylib 0x000000012f5650c7 Java_com_sun_glass_ui_mac_MacPasteboard__1putItemsFromArray + 2439
8 ??? 0x00000001140bec90 0x0 + 4631293072
9 ??? 0x00000001140b8a90 0x0 + 4631267984
10 ??? 0x00000001140b8a90 0x0 + 4631267984
11 ??? 0x00000001140b8a90 0x0 + 4631267984
)
libc++abi.dylib: terminating with uncaught exception of type NSException
这是我可以找到解决方法的问题,还是在Java / JavaFX / macOS集成中遇到了实际问题?
- OS:macOS Catalina(10.15.1)
- JDK:openjdk-13.0.1