Summary
Add an API that allows a developer to specify a list of persistent menus in the system menu bar, replacing the default application menu.
Problem
On macOS the application menu is the menu adjacent to the Apple logo menu. It's title matches the name of the active application and it contains standard items like "Quit", "Hide AppName", "Hide Others", and "Show All".
When not embedded JavaFX installs a default application menu which is not accessible via any API calls and cannot be modified in any way. In particular it cannot be localized and clients cannot add items that are commonly present in this menu like "About" or "Settings". Also the "Quit" item works incorrectly when Platform.setImplicitExit() is set to 'false' and this behavior cannot be modified and the "Quit" menu item can't be removed.
The application menu is persistent and is present whether or not a JavaFX window contains a MenuBar that has useSystemMenu set to true. If the currently focused JavaFX window contains such a MenuBar the menus in that MenuBar appear alongside the application menu. The application menu is also present even if no JavaFX window has focus (e.g. they are all iconified) in which case it's the only menu in the system menu bar.
Solution
The solution is to provide a static property specifying a list of menus to replace the application menu. The list is an ObservableList of standard JavaFX Menu controls known as the "common" menus.
It would be sufficient to provide a single menu rather than a list but there's no technical reason to limit this to just one menu. A list would also allow a developer to duplicate the standard macOS menu bar behavior where a single set of menus are installed at application launch and persist throughout the lifetime of the application (as opposed to the per-window behavior currently modeled in JavaFX).
Like the current application menu, the common system menus would always be present. If the currently focused JavaFX window contains a MenuBar and has useSystemMenus set those menus would appear alongside the common system menus.
An alternative would be to follow the lead of AWT and provide API's to customize aspects of the application menu such as providing new titles and behaviors for the pre-installed menu items. This approach was probably necessary in the past (before OS X 10.6) when the application menu required special handling in the platform code. Since 10.6 the application menu can be handled like any other menu.
Another alternative is to allow developers to simply hide the default application menu so they can incorporate their own into their MenuBars (the first Menu in the MenuBar would become the application menu). This approach would require developers to build their MenuBars differently on macOS than on other platforms; the macOS versions would all need to have an additional application menu prepended to the front of the menu list. If no JavaFX window has focus there would be no active MenuBar to provide an application menu so JavaFX would have to reinstate the default application menu. Alternatively JavaFX could leave the last focused window's menus in the system menu bar when it lost focus similar to the way AWT works.
Specification
The detailed changes. Acceptable normative formats include inline patches, attached webrevs, and attached specdiffs or apidiffs. The names of attached files are recommended to include a bug id. References to external webservers, such as https://cr.openjdk.org/ and https://git.openjdk.org/, can be provided as informative supplements for the convenience of reviewers, but must be accompanied by a normative form of the specification directly associated with the CSR issue to satisfy archival purposes.
- csr of
-
JDK-8366568 Allow replacing built in application menu in system menu bar
-
- Open
-