# VTK + Java + Mac + Swing

**URL:** https://discourse.vtk.org/t/vtk-java-mac-swing/2794
**Category:** Support
**Created:** [March 10, 2020, 5:44pm UTC](https://discourse.vtk.org/t/vtk-java-mac-swing/2794 "2020-03-10T17:44:23Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![martinspel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/ecd19e/32.png) [@martinspel](https://discourse.vtk.org/u/martinspel)
#### Post date: [March 10, 2020, 5:44pm UTC](https://discourse.vtk.org/t/vtk-java-mac-swing/2794/1 "2020-03-10T17:44:23Z")

</div>

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 ?

---

<div class="post-metadata">

### Author: ![Marco](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marco/32/1461_2.png) [@Marco](https://discourse.vtk.org/u/Marco)
#### Post date: [March 11, 2020, 4:24pm UTC](https://discourse.vtk.org/t/vtk-java-mac-swing/2794/2 "2020-03-11T16:24:38Z")

</div>

Hello.  
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?

Regards,

Marco

---

<div class="post-metadata">

### Author: ![martinspel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/ecd19e/32.png) [@martinspel](https://discourse.vtk.org/u/martinspel)
#### Post date: [March 19, 2020, 3:01pm UTC](https://discourse.vtk.org/t/vtk-java-mac-swing/2794/3 "2020-03-19T15:01:15Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Marco](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marco/32/1461_2.png) [@Marco](https://discourse.vtk.org/u/Marco)
#### Post date: [March 19, 2020, 9:09pm UTC](https://discourse.vtk.org/t/vtk-java-mac-swing/2794/4 "2020-03-19T21:09:00Z")

</div>

Hello,

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](https://discourse.vtk.org/t/rendering-interaction-issues-with-vtk-8-2-java-jogl-on-windows/2781) 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:

> [@vtk8.2 build/run problems on Mac with Java](https://discourse.vtk.org/t/vtk8-2-build-run-problems-on-mac-with-java/932):
>
> I can successfully build vtk8.2 on mac. However, when I go to run the JoglConeRendering demo, I get the attached core dump. [hs\_err\_pid93111.log](https://discourse.vtk.org/uploads/default/original/1X/3cec68cd637ea2da39990ea1cc76816016fccae8.log) (77.8 KB) If I run things with the vtk8.1 prepackaged jar and libs that @Sebastien_Jourdain sent me, this works fine. So I’m confused why we’re getting a crash. I thought it might have something to do with our patching I’ve talked about in other posts, but clearly it doesn’t. For completeness, here’s the portion of the (modified) build script from t…

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

---

<div class="post-metadata">

### Author: ![Gilthalas](https://discourse.vtk.org/user_avatar/discourse.vtk.org/gilthalas/32/362_2.png) [@Gilthalas](https://discourse.vtk.org/u/Gilthalas)
#### Post date: [March 25, 2020, 3:48am UTC](https://discourse.vtk.org/t/vtk-java-mac-swing/2794/5 "2020-03-25T03:48:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Dennis](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/d/e56c9b/32.png) [@Dennis](https://discourse.vtk.org/u/Dennis)
#### Post date: [May 25, 2022, 10:56am UTC](https://discourse.vtk.org/t/vtk-java-mac-swing/2794/6 "2022-05-25T10:56:31Z")

</div>

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.  
 ![picture](https://discourse.vtk.org/uploads/default/original/2X/c/c3fedecf5816bd95de4e886f899589a39ab4f4c8.png)

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:

 ![picture_2](https://discourse.vtk.org/uploads/default/original/2X/b/b733b066149e1052cc981568716cee44d55407a7.png)

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?

---

<div class="post-metadata">

### Author: ![Martin3d](https://discourse.vtk.org/user_avatar/discourse.vtk.org/martin3d/32/4303_2.png) [@Martin3d](https://discourse.vtk.org/u/Martin3d)
#### Post date: [March 14, 2023, 1:48pm UTC](https://discourse.vtk.org/t/vtk-java-mac-swing/2794/7 "2023-03-14T13:48:23Z")

</div>

Hi,

A recent versions of JOGL, at least [the one I patched to work for macOS M1](https://discourse.vtk.org/t/fixed-vtk-java-wrappers-on-macos/7467), 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](https://discourse.vtk.org/t/vtk-9-1-available-as-maven-dependency/9371). It will bring JOGL 2.4 + VTK 9.1
