How can i add the default menu bar to a uifigure?

14 ビュー (過去 30 日間)
Pia Lützen
Pia Lützen 2023 年 5 月 4 日
コメント済み: Pia Lützen 2023 年 5 月 5 日
Dear designers,
for my code i am creating a uifigure, which does not show the default menu (and tool) bar that comes with a regular figure.
I know that i can create a menu bar using uimenu. However, i just want the same possibilities offered with figure, without having to code everything extra.
Is there a simple way to add the default menu bar to a uifigure?
Thanks a lot!

採用された回答

Dinesh
Dinesh 2023 年 5 月 4 日
Hello there,
Unfortunately, there is no simple way to add the default menu bar of a regular figure to a uifigure.
UIFigures and traditional figures use different rendering engines and have separate sets of supported components. UIFigures use web based components that are not supported with the menu bar of normal figures.
But, as you mentioned, it is possible to implement a similar menu bar in uifigure using uimenu. And yes, it requires additional coding effort to make this happen. But it allows you to customize as you would want it to be and there is more flexibility.
Here's an example to create a simple menu bar with File and Edit options in a uifigure.
% Create a uifigure
fig = uifigure;
% Create a File menu
fileMenu = uimenu(fig, 'Text', 'File');
% Add menu items to the File menu
uimenu(fileMenu, 'Text', 'New', 'MenuSelectedFcn', @(src, event) disp('New selected'));
uimenu(fileMenu, 'Text', 'Open', 'MenuSelectedFcn', @(src, event) disp('Open selected'));
uimenu(fileMenu, 'Text', 'Save', 'MenuSelectedFcn', @(src, event) disp('Save selected'));
uimenu(fileMenu, 'Text', 'Save As', 'MenuSelectedFcn', @(src, event) disp('Save As selected'));
% Create an Edit menu
editMenu = uimenu(fig, 'Text', 'Edit');
% Add menu items to the Edit menu
uimenu(editMenu, 'Text', 'Undo', 'MenuSelectedFcn', @(src, event) disp('Undo selected'));
uimenu(editMenu, 'Text', 'Cut', 'MenuSelectedFcn', @(src, event) disp('Cut selected'));
uimenu(editMenu, 'Text', 'Copy', 'MenuSelectedFcn', @(src, event) disp('Copy selected'));
uimenu(editMenu, 'Text', 'Paste', 'MenuSelectedFcn', @(src, event) disp('Paste selected'));
You can add more menu items and customize the 'MenuSelectedFcn' callbacks based on your application's needs.
  1 件のコメント
Pia Lützen
Pia Lützen 2023 年 5 月 5 日
thanks for the explanation and example!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by