Skip to content

MenuItem

Selectable menu entry supporting regular actions, checkboxes, commands, keyboard shortcuts, or cascading submenus.

Overview

Selectable menu entry supporting regular actions, checkboxes, commands, keyboard shortcuts, or cascading submenus. Provides extensive layout configuration and interaction capabilities.

Basic Usage

MenuItem item = MenuItem.action("Save", this::save)
    .shortcutText("Ctrl+S");
  • Menu: Floating popup or dropdown menu widget hosting a vertical stack of menu items, command triggers, and separators.
  • MenuBar: Top-level horizontal menu bar hosting dropdown menus with command binding, keyboard accelerators, and popup coordination.

API

MenuItem::action()

Returns the callback runnable executed when this item is clicked.

Returns Runnable: The item action callback..

MenuItem::action(Runnable)

Sets the callback runnable executed when this item is clicked.

Parameter Type Description
action Runnable The action callback.

Returns MenuItem: This instance for chaining..

MenuItem::action(String, Runnable)

Creates an action menu item with display label and click callback.

Parameter Type Description
label String The label text.
action Runnable The action callback.

Returns MenuItem: The created MenuItem instance..

MenuItem::checked()

Returns true if this item displays a checkmark indicator.

Returns boolean: True if checked; false otherwise..

MenuItem::checked(boolean)

Sets whether this item displays a checkmark indicator.

Parameter Type Description
checked boolean The checked state.

Returns MenuItem: This instance for chaining..

MenuItem::command(String)

Creates a command menu item linked to an editor command identifier.

Parameter Type Description
commandId String The command identifier.

Returns MenuItem: The created MenuItem instance..

MenuItem::command(String, String)

Creates a command menu item with an explicit custom label.

Parameter Type Description
commandId String The command identifier.
label String The label text.

Returns MenuItem: The created MenuItem instance..

MenuItem::commandId()

Returns the linked editor command identifier.

Returns String: The result value..

MenuItem::commandId(String)

Sets the linked editor command identifier.

Parameter Type Description
commandId String The command identifier.

Returns MenuItem: This instance for chaining..

MenuItem::enabled()

Returns true if this item is interactive and clickable.

Returns boolean: True if enabled; false otherwise..

MenuItem::enabled(boolean)

Sets whether this item is interactive and clickable.

Parameter Type Description
enabled boolean Whether the feature or item is enabled.

Returns MenuItem: This instance for chaining..

MenuItem::kind()

Returns the kind of this menu item (ACTION, COMMAND, SEPARATOR, SUBMENU).

Returns Kind: The menu item kind..

MenuItem::label()

Returns the item display label text.

Returns String: The label string..

MenuItem::label(String)

Sets the item display label text.

Parameter Type Description
label String The label text.

Returns MenuItem: This instance for chaining..

Sets the nested submenu container.

Parameter Type Description
submenu Menu The child submenu.

Returns MenuItem: This instance for chaining..

MenuItem::separator()

Creates a visual divider separator item.

Returns MenuItem: The created MenuItem instance..

MenuItem::shortcutText()

Returns the shortcut key combination display text.

Returns String: The shortcut accelerator string..

MenuItem::shortcutText(String)

Sets the shortcut key combination display text.

Parameter Type Description
shortcutText String The shortcut label text.

Returns MenuItem: This instance for chaining..

Returns the nested submenu, or null if not a submenu item.

Returns Menu: The child submenu, or null if none..

Creates a cascading submenu item.

Parameter Type Description
submenu Menu The child submenu.

Returns MenuItem: The created MenuItem instance..