MenuBar
Declares the menu bar of the window whose content this is composed in.
This is declared on WindowScope, the receiver of the content of a Window and of a Dialog, so it is only available where there is a window to carry the bar.
content is a menu tree - Menu, MenuItem, CheckBoxMenuItem, RadioButtonMenuItem, MenuSeparator - and the menus it declares run across the top of the window:
Window(onCloseRequest = ::exitApplication) {
MenuBar {
Menu("File") {
MenuItem("Open", onClick = { open() })
MenuSeparator()
MenuItem("Exit", onClick = ::exitApplication)
}
}
Label("Ready")
}The menu tree shares the surrounding composition, so a menu item shows the current state and its callback writes that state like any other composable callback. The bar is on the window for as long as this is in the composition; once this leaves, the window carries the bar it carried before, so a window whose menu bar comes and goes is an ordinary if around the call.
A window carries one menu bar, so one declaration serves a window: put the choice of menus inside the declaration rather than composing a second one for the same window, which fails and leaves the window the bar it carried.
Parameters
the composable menu tree shown as the window's menu bar.