Drag Drop Swing to JavaFX not working without debug mode

柔情痞子 提交于 2021-01-28 14:10:23

问题


I have a code that gets a Drag event coming from a Swing application. The code then drop the elements into a JavaFX TableView.

This code works perfectly if I run in Debug mode. But it does not work if I run out of Debug.

private static final DataFormat customFormat = new DataFormat("application/x-java-serialized-object");

this.setOnDragOver(new EventHandler<DragEvent>() {
    public void handle(DragEvent event) {
        event.acceptTransferModes(TransferMode.ANY);
        event.consume();
    }
});

this.setOnDragDropped(new EventHandler<DragEvent>() {
    public void handle(DragEvent event) {
        try {
            Dragboard db = event.getDragboard();
            if (db == null) {
                alertInfo();
            } else {
                MyClassObject res = (MyClassObject) db.getContent(customFormat);
                // do stuffs
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
        } finally {
            event.setDropCompleted(true);
            event.consume();
        }
    }
}

I know the error is in the "MyClassObject res = (MyClassObject) db.getContent (customFormat);" line, because the return exception when it fails is "java.lang.String can not be cast to MyClassObject".

However, in debug this error does not occur. The cast is successful!

Has anyone ever experienced it?


回答1:


It seems related with Java cache. The code runs correctly after clean all cache in Java Control.



来源:https://stackoverflow.com/questions/56601349/drag-drop-swing-to-javafx-not-working-without-debug-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!