网页 综合 更新时间 2026-11-13 21:53:25

Menu | Electron

自动蜘蛛 www.electronjs.org 正文约 3694 字
Create application menus and context menus.
The presentation of menus varies depending on the operating system:
See also: A detailed guide about how to implement menus in your application.
Electron's built-in classes cannot be subclassed in user code. For more information, see the FAQ.
The Menu class has the following static methods:
Sets menu as the application menu on macOS. On Windows and Linux, the menu will be set as each window's top menu.
On Linux, the menu bar uses GTK theme colors when GTK is available. If GTK cannot initialize, it uses Chromium's built-in light or dark menu colors, following nativeTheme.shouldUseDarkColors.
Also on Windows and Linux, you can use a & in the top-level item name to indicate which letter should get a generated accelerator. For example, using &File for the file menu would result in a generated Alt-F accelerator that opens the associated menu. The indicated character in the button label then gets an underline, and the & character is not displayed on the button label.
In order to escape the & character in an item name, add a preceding &. For example, &&File would result in &File displayed on the button label.
Passing null will suppress the default menu. On Windows and Linux, this has the additional effect of removing the menu bar from the window.
The default menu will be created automatically if the app does not set one. It contains standard items such as File, Edit, View, and Window.
Returns Menu | null - The application menu, if set, or null, if not set.
The returned Menu instance doesn't support dynamic addition or removal of menu items. Instance properties can still be dynamically modified.
Sets the colors used to highlight the hovered or keyboard-focused item in every menu the app shows, including context menus and the menu bar's dropdowns. Light and dark colors are set separately, and any color left unset keeps the default for that mode. Each call replaces the colors set by any previous call. Passing null restores the defaults.
Menus opened after the call use the new colors. The colors are not applied while Windows high contrast mode or forced colors are active, so the user's system colors take priority.
This method has no effect on macOS and Linux.
Sends the action to the first responder of application. This is used for emulating default macOS menu behaviors. Usually you would use the role property of a MenuItem.
See the macOS Cocoa Event Handling Guide for more information on macOS' native actions.
Generally, the template is an array of options for constructing a MenuItem. The usage can be referenced above.
You can also attach other fields to the element of the template and they will become properties of the constructed menu items.
The menu object has the following instance methods:
Pops up this menu as a context menu in the BaseWindow.
For more details, see the Context Menu guide.
Closes the context menu in the window.
Appends the menuItem to the menu.
Returns MenuItem | null - the item with the specified id
Inserts the menuItem to the pos position of the menu.
Objects created with new Menu or returned by Menu.buildFromTemplate emit the following events:
Some events are only available on specific operating systems and are labeled as such.
Emitted when menu.popup() is called.
Emitted when a popup is closed either manually or with menu.closePopup().
menu objects also have the following properties:
A MenuItem[] array containing the menu's items.
Each Menu consists of multiple MenuItem instances and each MenuItem can nest a Menu into its submenu property.
The OpenJS Foundation | Terms of Use | Privacy Policy | Bylaws | Code of Conduct | Trademark Policy | Trademark List | Cookie Policy
访问原文 返回搜索 https://www.electronjs.org/docs/latest/api/menu
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。