Drag and Drop working differently in Java 11 vs Java 8

While Drag and Drop in JavaFX has a common API for all the platforms (as the rest of the API, of course), its internal implementation is platform dependent, and it is quite different on Windows, Mac or Linux.

But this shouldn’t be an issue when migrating from JavaFX 8 to JavaFX 11, though.

The sample posted by the OP works the same on Windows and Mac with both JavaFX 8 and 11, and if it is not the case on Linux, it might have to do with the changes done in the latest release of JavaFX for Linux.

According to the releases note, under the Important Changes section we can see:

Switch default GTK version to 3

JavaFX will now use GTK 3 by default on Linux platforms where the gtk3 library is present. Prior to JavaFX 11, the GTK 2 library was the default. This matches the default for AWT in JDK 11. See JDK-8198654 for more information.

While this change was basically a two lines diff in the JavaFX code, and nothing changed from the implementation details for DND, the GTK 3 implementation might have changed from GTK 2, and those changes haven’t been taken into account.

Similar issues related to GTK have been reported for dialogs, windows or Wayland crashes.

Workaround

So far the only known workaround for all of those issues is to run the app with GTK 2, that can be set with the system property: jdk.gtk.version.

So this option can be added on command line:

java -Djdk.gtk.version=2 ...

to run the application.

As posted in the comments, this seems to solve the drag and drop issue.

Report the issue

Definitely, that confirms that this is an issue, and as such it should be filed at the OpenJFX issue tracker, providing the sample code to reproduce it, system details (OS version, Java version, JavaFX version…).

Leave a Comment