VTK + Java + Mac + Swing

Compiling on a Mac (Catalina) with Java bindings, the following error is produced:
2020-03-10 18:39:49.820 java[89250:2491420] WARNING: NSWindow drag regions should only be invalidated on the Main Thread! when launching from Eclipse.

Running with the JVM option -XstartOnFirstThread solves the problem, but causes the Swing based GUI to block.

Has anyone run into this issue ?

Are you using JOGL as the method used by VTK to render to Java panels?

As far as I know, starting from Java 7 (JDK 1.7, i.e., the first non-Apple JDK on MacOS), VTK won’t be able to “directly” render to Java panels through the JAWT interface, due to some changes in the JDK packages/classes and in the related native interfaces.
Hence, right now, the only option left to use VTK with Java on MacOS is by using JOGL (at least, if you need VTK rendering / interaction functionalities).

So, you will need to download JOGAMP, and then build VTK with JOGL options enabled and related CMake settings appropriately setup.

Are you already working this way, i.e., with JOGL?



Yes, I’m using JOGL.
In order to run I need the -XstartOnFirstThread jvm option, but apparently Swing doesn’t like that.
I didn’t manage to find a working example of this combination of Java Swing + VTK under OSX.


I will also need to “fight” with VTK + Java + JOGL + Swing on Mac in the upcoming weeks, so maybe I will be able to share my experience on that environment as well.

As of now, I am working with JOGL on Windows, and I am already encountering some issues unfortunately (see Rendering/interaction issues with VTK 8.2 (Java) + JOGL on Windows for details).

Regarding your problem, you told that the Swing GUI will block if you launch your application with the “-XstartOnFirstThread” JVM parameter. Can you provide more details? When will the Swing GUI block? As soon as the Swing GUI shows up on screen? Will it lock forever, or what?

Please provide some more details, I will check if I have suggestions to provide.

Also, you may want to take a look at this thread:

Not sure if this user was indeed using Swing in his application, but it looks like he was successful in having VTK 8.2 + Java + JOGL to work under macOS.

Best regards,

Marco Sambin

That warning comes from JOGL. I have built 8.2 with more bleeding edge jogl jars and that warning goes away. I’m curious what the 9.0 build will depend on (assuming they have java bindings enabled). I’ll try to update my other thread with some details in the next few days as to what needs to be done, and also put in a merge request for the changes.

1 Like

Hi all, currently I am struggling to get VTK to run with Java support on macOS. I have successfully compiled VTK with openJDK 11.

In ccmake I have selected the following options for the compilation.

Unfortunately, I currently get the “NSWindow drag regions should only be invalidated on the Main Thread!’” error. As I read above, I need to include jogl and include the -XstartOnFirstThread jvm argument.

I am using IntelliJ and the -XstartOnFirstThread I have included here:

What is the best way to insert jogl now? Should I enable the VTK_JAVA_JOGL_COMPONENT option in ccmake and then insert the jogl library in IntelliJ?


A recent versions of JOGL, at least the one I patched to work for macOS M1, is able to pick the macOS main thread on his own without having to use the -XstartOnFirstThread flag - which make Swing usable again. This JOGL version also fixes a number of issue with JOGL on macOS.

If you want to give a try easily, maybe you can use the maven packages I mentioned here. It will bring JOGL 2.4 + VTK 9.1