How can i add the default menu bar to a uifigure?
14 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!