PopupMenu
A menu the application opens itself - a drop-down button, an overflow menu, a shortcut - shown over the component anchor is bound to.
The menu is open while expanded is true. Closing is the toolkit's own doing and cannot be refused: adopt the close onDismiss reports by setting expanded back to false, or the next true declares nothing new and the menu stays shut.
val anchor = rememberPopupAnchor()
var expanded by remember { mutableStateOf(false) }
Button("File", onClick = { expanded = true }, modifier = SwingModifier.popupAnchor(anchor))
PopupMenu(anchor, expanded, onDismiss = { expanded = false }) {
MenuItem("Open", onClick = { })
}The menu's items are a composition of their own, nested in this one, so they see the same state and androidx.compose.runtime.CompositionLocals as this call. They are composed when the menu opens and released when it closes, and a menu on screen follows the state its items read.
A menu declared open against an anchor that is not bound yet - or bound to a component not yet on screen - waits and opens once there is somewhere to anchor to.
For the menu a right-click opens, use ContextMenu.
Parameters
the handle naming the component the menu opens over, bound with popupAnchor.
whether the menu is open.
invoked when the user closes the menu.
the composable menu tree shown in the menu.
See also
Variant of PopupMenu that lets the caller decide how the populated JPopupMenu is presented, instead of the default of showing it at the anchor point under the bound component.
Parameters
the handle naming the component the menu opens over.
whether the menu is open.
invoked with the populated popup, the anchored component, and the anchor point (x, y in that component's coordinates) to present the popup.
invoked when the user closes the menu.
the composable menu tree shown in the menu.