Azzera filtri
Azzera filtri

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

24 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

Dinesh
Dinesh il 4 Mag 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.

Più risposte (0)

Categorie

Scopri di più su Develop uifigure-Based Apps in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by