Any workaround for Java/Swing bug under Mac OS when opening new windows as tabs

Tags: , ,



I’m developing a swing based Java application (Java 8) for Mac and Windows. Some users have set the mac system preference under “General” “Prefer Tabs when opening documents” to “Always” or “Full screen”. When the setting is set to “Never” it works without problems.

enter image description here

This setting causes some weird state in which the window opens a new tab which results in a frozen application which can only be force quitted. I cannot assume that users know about this hidden setting in the Mac OS system preferences.

enter image description here

Three solutions would work for me:

  • Find any workaround to prevent the window from opening other windows as tabs?
  • Launching our bundled Java app with some -flag that disables this behaviour for the entire application
  • Detecting if this mac system setting is enabled and then warn the user and quit the application (not really a good solution)

Answer

This change in Big Sur is causing a bug in Java https://bugs.openjdk.java.net/browse/JDK-8256465

There is a workaround from MacOS terminal window you can run

defaults write net.java.openjdk.cmd "AppleWindowTabbingMode" manual

or if you have java bundled within your own application use the value of CFBundleIdentifier in the applications Info.plist file

e.g

defaults write net.myapp.com "AppleWindowTabbingMode" manual


Source: stackoverflow