Skip to main content

Deadlock in JavaFX when using JGraphX Swing component

By 25 oktober 2014januari 30th, 2017No Comments

Combining JavaFX and old Swing components can be tricky. For example, when changing JavaFX data from the Swing component you have to remember to wrap your code in a Runnable and call it using
Platform.runLater . For the reverse, you’d have to use SwingUtilities.invokeLater.

I was working on a project using both JavaFX and a graph component called JGraphX. This is a complex component which allows you to edit graph models. I was using an old version (JGraph 5) before but since that hasn’t been maintained and had some bugs I couldn’t work around (e.g. unable to change the edge ending graphics), I decided to upgrade. After I ported the API calls, I fired up the application and was faced with a frozen application. It deadlocked.

Running it in debug mode quickly pointed me to the culprit:

Screen Shot 2014-10-25 at 18.12

Apparently there was a lock on the mouse position being kept by Swing. It looks to be in native code as well so chances are that it is Mac OS X specific.

I was running JDK 1.8.0_20 at the time which was the latest and greatest version. I ended up disabling most of the user interaction on the component (I didn’t need it anyway) on the JGraphX component using something like this:

private void makeReadonly(JGraphXAdapter graph, mxGraphComponent graphComponent) {

For me, this solved the deadlock: whereas it triggered 9 times out of 10 before, it hasn’t triggered yet.

Update: JDK 1.8.0_25 seems to solve the problem as well.