I'm supporting a Java swing application which uses the DJ-Native-Swing web browser.
The application uses swing menus (JMenu etc.) and we specify -Dapple.laf.useScreenMenuBar=true at runtime so that the menus appear in the Mac menu bar (at the top of the screen) instead of within the JFrame.
We recently had reports that our application was crashing at launch on some recent Macs - specifically we have been testing with a late 2016 Macbook Pro w/touch bar which has this problem. We have resolved this by taking a newer version of DJ-Native-Swing. We have found that this commit (https://github.com/Chrriis/DJ-Native-Swing/commit/7a68a882f0a5ff0a1ba5edae57f2655b853a0748) fixes the crash by re-ordering initialization so that all Swing/AWT initialization happens after SWT initialization. Previously we had been using DJ-Native-Swing version 1.0.1 which we took in around 2011.
Unfortunately this commit has the side-effect that on all Macs our Swing menu bar appears within the JFrame, i.e. it seems like Swing is ignoring apple.laf.useScreenMenuBar.
What I have found so far is:
- both problems seem directly related to the order of initialization between Swing and SWT. If we reorder code to call Toolkit.getDefaultToolkit() before the SWT initialization then this both re-introduces the crash and fixes the menu bar problem.
- the menu bar problem is fixed if we use Java 8 update 31 or earlier. I suspect this fix (http://bugs.java.com/view_bug.do?bug_id=8048549) in Java 8 update 40.
So if I understand correctly:
- recent Macs crash unless SWT is initialized before Swing.
- but if SWT is initialized before Swing, the JDK fix means that Swing detects (when it is initialized?) that there is another UI framework running and if so it ignores useScreenMenuBar.
We are not comfortable using an old JDK version since this will leave us without recent security fixes. I have considered whether we can patch the relevant JDK code in com.apple.laf.AquaMenuBarUI but there seem to be license restrictions about distributing a modified JDK (not to mention introducing a maintainability problem for the future).
I also found a related bug from 2010 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=307302).
Has anyone else seen this issue or found a good resolution?
Appreciate any help.
Thanks,
Matt
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Mac was always problematic. My last impression was that DJ Native Swing did not work anymore after oracle changed some things for Java 7. https://bugs.eclipse.org/bugs/show_bug.cgi?id=418245
I am surprised that you are using Java 8 and that it works. Am I getting confused, or did things changed maybe to support JavaFX?
About solving this issue, it seems to involve SWT, AWT, apple toolkit and maybe Java FX team. You should open a bug on each platform with a simple test case showing the issue and include the links to the various related issues you found. It would help if that test case were a pure SWT/AWT implementation; you could try to start from: http://www.nextencia.net/SWTAWTExample.java
Please, let us know the bugs you opened so we can track them.
Cheers,
-Christopher
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Matt. I just posted a message about having problems running on the new Mac with the Touchbar. Can you tell me, did you move from the 1.0.1 DJ core to 1.0.3 Preview, or 1.0.2? Also, you are able to run on the new Java8 VM? When I tried it crashed when attempting to load an HTML Editor instance. When I googled the error the impression I got was that Oracle no longer supported something needed with heavyweight components or something like that. So you really are running a Web Browser instance on Java 8 on a Mac with a Touchbar? I would really like to get to where you are.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm supporting a Java swing application which uses the DJ-Native-Swing web browser.
The application uses swing menus (JMenu etc.) and we specify -Dapple.laf.useScreenMenuBar=true at runtime so that the menus appear in the Mac menu bar (at the top of the screen) instead of within the JFrame.
We recently had reports that our application was crashing at launch on some recent Macs - specifically we have been testing with a late 2016 Macbook Pro w/touch bar which has this problem. We have resolved this by taking a newer version of DJ-Native-Swing. We have found that this commit (https://github.com/Chrriis/DJ-Native-Swing/commit/7a68a882f0a5ff0a1ba5edae57f2655b853a0748) fixes the crash by re-ordering initialization so that all Swing/AWT initialization happens after SWT initialization. Previously we had been using DJ-Native-Swing version 1.0.1 which we took in around 2011.
Unfortunately this commit has the side-effect that on all Macs our Swing menu bar appears within the JFrame, i.e. it seems like Swing is ignoring apple.laf.useScreenMenuBar.
What I have found so far is:
- both problems seem directly related to the order of initialization between Swing and SWT. If we reorder code to call Toolkit.getDefaultToolkit() before the SWT initialization then this both re-introduces the crash and fixes the menu bar problem.
- the menu bar problem is fixed if we use Java 8 update 31 or earlier. I suspect this fix (http://bugs.java.com/view_bug.do?bug_id=8048549) in Java 8 update 40.
So if I understand correctly:
- recent Macs crash unless SWT is initialized before Swing.
- but if SWT is initialized before Swing, the JDK fix means that Swing detects (when it is initialized?) that there is another UI framework running and if so it ignores useScreenMenuBar.
We are not comfortable using an old JDK version since this will leave us without recent security fixes. I have considered whether we can patch the relevant JDK code in com.apple.laf.AquaMenuBarUI but there seem to be license restrictions about distributing a modified JDK (not to mention introducing a maintainability problem for the future).
I also found a related bug from 2010 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=307302).
Has anyone else seen this issue or found a good resolution?
Appreciate any help.
Thanks,
Matt
Hi Matt,
Mac was always problematic. My last impression was that DJ Native Swing did not work anymore after oracle changed some things for Java 7.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=418245
I am surprised that you are using Java 8 and that it works. Am I getting confused, or did things changed maybe to support JavaFX?
About solving this issue, it seems to involve SWT, AWT, apple toolkit and maybe Java FX team. You should open a bug on each platform with a simple test case showing the issue and include the links to the various related issues you found. It would help if that test case were a pure SWT/AWT implementation; you could try to start from:
http://www.nextencia.net/SWTAWTExample.java
Please, let us know the bugs you opened so we can track them.
Cheers,
-Christopher
Hi Christopher,
Thanks for the response. I will try and find the time to write a simple test case and raise those bugs!
Matt
Hi Matt. I just posted a message about having problems running on the new Mac with the Touchbar. Can you tell me, did you move from the 1.0.1 DJ core to 1.0.3 Preview, or 1.0.2? Also, you are able to run on the new Java8 VM? When I tried it crashed when attempting to load an HTML Editor instance. When I googled the error the impression I got was that Oracle no longer supported something needed with heavyweight components or something like that. So you really are running a Web Browser instance on Java 8 on a Mac with a Touchbar? I would really like to get to where you are.