
Declarative DSL building native menu bars with cross‑platform fallbacks, shortcut and icon helpers, per‑platform visibility flags, out‑of‑the‑box macOS defaults and localized labels.
Advanced-MenuBar is a Compose Desktop (JVM) library that replaces the default macOS menu bar integration with a declarative DSL. It provides native macOS menus, shortcut handling and fallbacks for Windows and Linux so your desktop apps can ship with a consistent menu experience.
AdvancedMacMenu, including application, file, edit, format, view, window, help, and custom menus driven by Compose state.CompatibilityMenu to render the same menu DSL through Compose MenuBar widgets on non-macOS hosts while still delegating to Cocoa on macOS.DefaultMacMenu, which also brings you the options to set callback of About, Settings and Help.MenuVisibility flags so your menus adapt automatically.rememberMenuIconFrom or define MenuShortcut values for keyboard access.Compose Advanced-MenuBar is published to Maven Central:
repositories {
mavenCentral()
}
dependencies {
implementation("dev.hansholz:advanced-menubar:<version>")
}@Composable
fun MacMenu(appName: String) {
AdvancedMacMenu(appName) {
MacApplicationMenu {
About { /* show about dialog */ }
Separator()
Settings { /* open settings */ }
Quit { /* optional custom quit */ }
}
MacFileMenu {
FileNew { createNewDocument() }
FileOpen { openExisting() }
Separator()
FileSave(enabled = fileChanged) { save() }
}
MacViewMenu {
ToggleFullScreen()
}
MacCustomMenu("Tools") {
Item("Reload Data", shortcut = MenuShortcut(Key.R, meta = true)) { reload() }
}
}
}AdvancedMacMenu rebuilds the Cocoa menu whenever Compose state changes, so enabling/disabling items and checkboxes is seamless.
@Composable
fun FrameWindowScope.CrossPlatformMenu(appName: String) {
CompatibilityMenu(appName) {
MacApplicationMenu {
About { /* ... */ }
Quit()
}
FileMenu {
FileOpen { /* ... */ }
FileSave { /* ... */ }
}
HelpMenu {
AppHelp { openHelpCenter() }
}
}
}On macOS this delegates to Cocoa; elsewhere the same DSL is rendered through Compose MenuBar.
DefaultMacMenu(
onAboutClick = { showAboutDialog() },
onSettingsClick = { openPreferences() },
onHelpClick = { openDocs() }
)DefaultMacMenu only runs on macOS and adds the most common menu entries (Application, View, Window, Help).
Use the optional visibility parameter in items from CompatibilityMenu to hide or show items depending on the host OS:
FileMenu {
FilePageSetup(visibility = MenuVisibility.MACOS_ONLY)
FilePrint { /* ... */ }
}val infoIcon = rememberMenuIconFrom(Icons.Rounded.Info)
CustomMenu("Help") {
Item("Documentation", macIcon = infoIcon) { openDocs() }
Item("Reload", shortcut = MenuShortcut(Key.R, meta = true)) { reload() }
}rememberMenuIconFrom rasterizes Compose vectors into template PNG bytes ready for the menu bar on macOS, while MenuShortcut converts to native key equivalents.
For the MenuIcons on MacOS can also SFSymbols, Pngs and Files be used.
The strings for the menu bars are localized using Compose Resources and the default language can be changed with Locale.setDefault(...).
Currently, the following languages are supported:
You can find a sample project in the sample directory. Run the following command to test it:
./gradlew :sample:runDistributableAdvanced-MenuBar is distributed under the Apache 2.0 license. See LICENSE.txt.
Advanced-MenuBar is a Compose Desktop (JVM) library that replaces the default macOS menu bar integration with a declarative DSL. It provides native macOS menus, shortcut handling and fallbacks for Windows and Linux so your desktop apps can ship with a consistent menu experience.
AdvancedMacMenu, including application, file, edit, format, view, window, help, and custom menus driven by Compose state.CompatibilityMenu to render the same menu DSL through Compose MenuBar widgets on non-macOS hosts while still delegating to Cocoa on macOS.DefaultMacMenu, which also brings you the options to set callback of About, Settings and Help.MenuVisibility flags so your menus adapt automatically.rememberMenuIconFrom or define MenuShortcut values for keyboard access.Compose Advanced-MenuBar is published to Maven Central:
repositories {
mavenCentral()
}
dependencies {
implementation("dev.hansholz:advanced-menubar:<version>")
}@Composable
fun MacMenu(appName: String) {
AdvancedMacMenu(appName) {
MacApplicationMenu {
About { /* show about dialog */ }
Separator()
Settings { /* open settings */ }
Quit { /* optional custom quit */ }
}
MacFileMenu {
FileNew { createNewDocument() }
FileOpen { openExisting() }
Separator()
FileSave(enabled = fileChanged) { save() }
}
MacViewMenu {
ToggleFullScreen()
}
MacCustomMenu("Tools") {
Item("Reload Data", shortcut = MenuShortcut(Key.R, meta = true)) { reload() }
}
}
}AdvancedMacMenu rebuilds the Cocoa menu whenever Compose state changes, so enabling/disabling items and checkboxes is seamless.
@Composable
fun FrameWindowScope.CrossPlatformMenu(appName: String) {
CompatibilityMenu(appName) {
MacApplicationMenu {
About { /* ... */ }
Quit()
}
FileMenu {
FileOpen { /* ... */ }
FileSave { /* ... */ }
}
HelpMenu {
AppHelp { openHelpCenter() }
}
}
}On macOS this delegates to Cocoa; elsewhere the same DSL is rendered through Compose MenuBar.
DefaultMacMenu(
onAboutClick = { showAboutDialog() },
onSettingsClick = { openPreferences() },
onHelpClick = { openDocs() }
)DefaultMacMenu only runs on macOS and adds the most common menu entries (Application, View, Window, Help).
Use the optional visibility parameter in items from CompatibilityMenu to hide or show items depending on the host OS:
FileMenu {
FilePageSetup(visibility = MenuVisibility.MACOS_ONLY)
FilePrint { /* ... */ }
}val infoIcon = rememberMenuIconFrom(Icons.Rounded.Info)
CustomMenu("Help") {
Item("Documentation", macIcon = infoIcon) { openDocs() }
Item("Reload", shortcut = MenuShortcut(Key.R, meta = true)) { reload() }
}rememberMenuIconFrom rasterizes Compose vectors into template PNG bytes ready for the menu bar on macOS, while MenuShortcut converts to native key equivalents.
For the MenuIcons on MacOS can also SFSymbols, Pngs and Files be used.
The strings for the menu bars are localized using Compose Resources and the default language can be changed with Locale.setDefault(...).
Currently, the following languages are supported:
You can find a sample project in the sample directory. Run the following command to test it:
./gradlew :sample:runDistributableAdvanced-MenuBar is distributed under the Apache 2.0 license. See LICENSE.txt.