On Thu, 12 Mar 2026 23:48:59 GMT, Jose Pereda <[email protected]> wrote:

> This PR fixes an issue on macOS with a system menu bar, that happens when a 
> dialog is shown while a menu from the system menu bar is also showing.
> 
> Currently the menubar is removed whenever the stage loses focus, but that 
> causes a broken state in the menu (as reported in 
> https://bugs.openjdk.org/browse/JDK-8335541) as the dialog showing prevents 
> for a clean tear down of the menubar. And even if there were no issues, there 
> is actually no need of destroying and recreating the same menubar all over 
> again, since nothing really changed (the dialog doesn't have a menubar on its 
> own, and shares the very same one from its owner stage).
> 
> A test has been added, that fails before this patch and passes with it. 
> Another minor test has been included, just to give some details about what 
> happens when a menu titled exactly `"Help"` is added to the system menu bar. 
> It works before and after the patch.
> 
> While adding the test, I noticed that there were failures when the menu was 
> hidden:
> 
> SystemMenuBarHelpMenuTest STANDARD_ERROR
>     Exception in thread "JavaFX Application Thread" 
> java.lang.IllegalStateException: Not on FX application thread; currentThread 
> = JavaFX Application Thread
>         at 
> javafx.graphics@27-internal/com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:282)
>         at 
> javafx.graphics@27-internal/com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:480)
>         at 
> javafx.controls@27-internal/javafx.scene.control.Menu.hide(Menu.java:428)
>         at 
> javafx.graphics@27-internal/com.sun.javafx.tk.quantum.GlassMenuEventHandler.handleMenuClosed(GlassMenuEventHandler.java:46)
>         at 
> javafx.graphics@27-internal/com.sun.glass.ui.Menu.notifyMenuClosed(Menu.java:196)
> 
> so I wrapped the calls in `Menu::notifyMenuClosed` and  
> `Menu::notifyMenuClosed`  with ` Utils::runOnFxThread`.

Currently when all windows in a JavaFX app are iconified they all lose focus 
and the system menu bar is reduced to a single menu (the built-in application 
menu). This is very strange behavior for a Mac application. With this PR when 
all windows are iconified the system menu bar will show menu bar of the last 
focused window to have focus. This is the same way AWT works. I prefer the AWT 
behavior but it does mean the user can invoke menu items while all the windows 
are iconified. I think this is a bigger change than a bug fix for a corner case 
and probably warrants a CSR. 

If you test with SceneBuilder you might not see the behavior I just described. 
There's a private API called setDefaultSystemMenuBar in the MenuBarSkin and 
according to the comment it's used by SceneBuilder to provide a system menu bar 
to display when all windows are closed. I think that same menu bar would be 
used when all windows are iconified as well (I haven't tested this).

BTW, I can't reproduce the original problem using the test app in 
[JDK-8335541](https://bugs.openjdk.org/browse/JDK-8335541) when I tested with 
macOS 15.7.4. When the dialog opens the Help menu reliably goes away for me. 
Which OS version are you testing with?

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

PR Comment: https://git.openjdk.org/jfx/pull/2107#issuecomment-4058834180

Reply via email to