RFR: 8359108: Mac - When Swing starts First, native application menu doesn't work for JavaFX [v9]

Andy Goryachev angorya at openjdk.org
Wed Jan 7 20:06:39 UTC 2026


On Mon, 29 Dec 2025 09:15:28 GMT, Pabulaner IV <duke at openjdk.org> wrote:

>> This pull request fixes the system menu bar on MacOS when combining windows of Swing and JavaFX.
>> 
>> # Behavior before
>> 
>> If for some reason You needed to initialize AWT before JavaFX and You wanted to install the system menu bar from the JavaFX side, this wasn't possible. This issue is persistent even when You didn't open a Swing window. 
>> 
>> One scenario where this kind of issue happens is when You use install4j (see https://www.ej-technologies.com/install4j). In this case AWT is initialized by install4j and therefore You can't use the JavaFX system menu bar anymore.
>> 
>> 
>> # Behavior after
>> 
>> The fix allows JavaFX to install a system menu bar even if it is initialized after AWT. This is achieved by only changing code inside JavaFX. Each JavaFX window stores the previously installed menu bar when gaining focus and will restore this menu bar if the focus was lost. This only happens if the system menu bar installed by the JavaFX window is still unchanged.
>> 
>> 
>> # Tests
>> 
>> This PR introduces tests for the system menu bar in addition to verifying its own behavior / changes. The tests include single- and multi-window tests while interacting with Swing. The tests ensure that the menu bar stays the same for each window, no matter how You switch focus between them.
>> 
>> 
>> # Additional benifits 
>> 
>> This fix is not specifically for AWT, but allows JavaFX to interact much more compatibly with other frameworks that make use of the system menu bar.
>> 
>> 
>> # Review from AWT
>> 
>> In the previous PR related to this one, the comment was made that the folks from AWT should take a look at this fix. It would be great and much appreciated if someone could initiate it.
>> 
>> 
>> # Add disable flag?
>> 
>> We could also add a flag to prevent JavaFX from installing a system menu bar for users who have found other fixes for their projects / setups. This could be used to restore the previous behavior when AWT is initialized first.
>> 
>> 
>> Co-Author: @FlorianKirmaier
>
> Pabulaner IV has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8359108: Mac - When Swing starts First, native application menu doesn't work for JavaFX

Some minor comments, one exception, and many tests hang on closing using the system menu, or the quit menu in the dock, or the close icon in the title bar.

tests/manual/systemmenu/MacOSSystemMenuJFXPanelSwingFirstTest.java line 61:

> 59: 
> 60:     public void test() throws InterruptedException, IOException {
> 61:         initSwing(List.of(TEST_MENUS_0, TEST_MENUS_1));

It would be nice to have some instructions / acceptance criteria in each test.
Assume the tester knows nothing about the issue.

tests/manual/systemmenu/MacOSSystemMenuMultiWindowTest.java line 57:

> 55:         new MacOSSystemMenuMultiWindowTest().test();
> 56:     }
> 57: 

I've got this upon exiting via system menu "Quit java" once:


Exception in thread "InvokeLaterDispatcher" java.lang.RuntimeException: Main Java thread is detached.
	at javafx.graphics at 26-internal/com.sun.glass.ui.mac.MacApplication._submitForLaterInvocation(Native Method)
	at javafx.graphics at 26-internal/com.sun.glass.ui.mac.MacApplication.submitForLaterInvocation(MacApplication.java:375)
	at javafx.graphics at 26-internal/com.sun.glass.ui.InvokeLaterDispatcher.run(InvokeLaterDispatcher.java:122)


Also, if I just launch it and then immediately select "Quit java" from the system menu, it hangs with a beach ball and requires ctrl-C in the terminal to kill it.

tests/manual/systemmenu/MacOSSystemMenuMultiWindowWithSwingFirstTest.java line 55:

> 53: 
> 54:     public static void main(String[] args) throws InterruptedException, IOException {
> 55:         new MacOSSystemMenuMultiWindowWithSwingFirstTest().test();

this test requires selecting SourceLauncher -> Quit java from the system menu twice to close - is this intentional?

tests/manual/systemmenu/MacOSSystemMenuMultiWindowWithSwingFirstTest.java line 62:

> 60:         initJavaFX(List.of(TEST_MENUS_1, TEST_MENUS_3));
> 61: 
> 62:         focusJavaFX(0);

Minor: noticed that the "Next" button seem to work only once in this and other tests.  Is it intentional?

tests/manual/systemmenu/MacOSSystemMenuSingleWindowWithSwingFirstTest.java line 56:

> 54: 
> 55:     public static void main(String[] args) throws InterruptedException, IOException {
> 56:         new MacOSSystemMenuSingleWindowWithSwingFirstTest().test();

this test hangs when fx window is closed first via the close title bar icon, followed by closing the swing window with same method.

tests/manual/systemmenu/README.md line 3:

> 1: # Compiling and Running
> 2: 
> 3: To compile the tests, run the following command:

Actually, separate compile step is not necessary, the test apps run with the following command from within this directory (you do need to run the gradle build first):


java --module-path ../../../build/sdk/lib/ --add-modules javafx.controls,javafx.fxml,javafx.swing MacOSSystemMenuJFXPanelSwingFirstTest.java

-------------

PR Review: https://git.openjdk.org/jfx/pull/1904#pullrequestreview-3636469005
PR Review Comment: https://git.openjdk.org/jfx/pull/1904#discussion_r2669807380
PR Review Comment: https://git.openjdk.org/jfx/pull/1904#discussion_r2669843101
PR Review Comment: https://git.openjdk.org/jfx/pull/1904#discussion_r2669882110
PR Review Comment: https://git.openjdk.org/jfx/pull/1904#discussion_r2669885390
PR Review Comment: https://git.openjdk.org/jfx/pull/1904#discussion_r2669899163
PR Review Comment: https://git.openjdk.org/jfx/pull/1904#discussion_r2669796415


More information about the openjfx-dev mailing list