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

16 vues (au cours des 30 derniers jours)
Pia Lützen
Pia Lützen le 4 Mai 2023
Commenté : Pia Lützen le 5 Mai 2023
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!

Réponse acceptée

Dinesh
Dinesh le 4 Mai 2023
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 commentaire
Pia Lützen
Pia Lützen le 5 Mai 2023
thanks for the explanation and example!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by