ContextMenu
The menu the platform's popup gesture opens over the component anchor is bound to - a right-click, or whatever else the look and feel gives that gesture, the keyboard binding included.
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 gesture opens the menu and released when it closes, and a menu on screen follows the state its items read.
val anchor = rememberPopupAnchor()
Label("Report", modifier = SwingModifier.popupAnchor(anchor))
ContextMenu(anchor) {
MenuItem("Copy", onClick = { })
}onClose reports the user closing the menu - selecting an item, pressing Escape, clicking away. A menu another gesture replaces, or that this declaration takes away by leaving the composition, is released without a close of its own.
The component's own popup menu is captured while this declaration stands and given back when it goes. One anchor carries one context menu: a second ContextMenu against the same anchor throws IllegalStateException as its declaration enters the composition.
For a menu the application opens itself, use PopupMenu.
Parameters
the handle naming the component the menu opens over, bound with popupAnchor. The component must be a JComponent; a bare Component carries no popup menu, and binding one throws IllegalStateException.
invoked when the menu has been put on screen.
invoked when the user closes the menu.
the composable menu tree shown in the popup.
See also
Variant of ContextMenu that lets the caller decide how the populated JPopupMenu is presented, instead of the default of showing it over the component at the trigger point.
Parameters
the handle naming the component the menu opens over.
invoked with the populated popup, the anchored component, and the trigger point (x, y in that component's coordinates) to present the popup.
invoked when the menu has been put on screen.
invoked when the user closes the menu.
the composable menu tree shown in the popup.