问题
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