Menu Bar in App Designer

24 views (last 30 days)
René Lampert
René Lampert on 27 Nov 2021
Commented: René Lampert on 1 Dec 2021
I have a question regarding the menues in the Menu Bar object in App Designer.
I try to explain it:
I have experienced the fact that when I have two menues - as an example - in the Menu Bar and click on one of them then a specific callback function gets executed - so far so good. But when I simply move the mouse over the second menu (without clicking on them) then the callback function of this menu gets executed (which can't be the correct behavior) . On the other hand, when I first click somewhere on the mouse then the coorect behavior occurs - which means that I have to click on the second menu such that the callback function gets executed.
Is there any property to change this strange behavior or is this a bug of Matlab itself? Does anyone have also experienced such a behavior or has some ideas which causes this problem?
Thanks in advance

Accepted Answer

Srijith Kasaragod
Srijith Kasaragod on 1 Dec 2021
Hi René,
This is the expected behavior of "UIMenu". Once "UIMenu" is activated by click and when the focus is moved to the adjacent menu, then the callback for that focused menu will be executed.
Kindly try the following workarounds to avoid this behaviour:
  • You can avoid this behavior by clicking outside of "UIMenu" and setting "UIMenu" out of focus .
  • You can create a utility which presses 'ESC' in the background every time a menu's callback is executed, returning control to the uifigure rather than the menu bar. This involves two steps:
%Create a Java robot object
import java.awt.Robot;
import java.awt.event.*;
robot = Robot;
% Trigger the 'ESC' key press event after a user selects a menu option, thus de-selecting that menu
robot.keyPress(java.awt.event.KeyEvent.VK_ESCAPE)
  • An alternative option would be to set the visibility of the figure 'off' and 'on' after calling each callback. This will 'refresh' the figure.
set(fHandle,'visible','off');pause(.01);set(fHandle,'visible','on');
Hope this helps!
  1 Comment
René Lampert
René Lampert on 1 Dec 2021
Hi Srijith,
thanks for your response. In my opinion this is a really odd behavior, but ok it is what it is. Your second alternative with the visible option is also not working, I tried it already before I wrote the question here. The first option sounds good, I will try it. I had this in mind but i thought that there must be another "easier" way to accomplish my task.
Thanks and best regards!

Sign in to comment.

More Answers (1)

René Lampert
René Lampert on 30 Nov 2021
I think what I meant with my question is incorporated in the following sentence
"While any menu is expanded, hovering any other parent menu (or top-level menu) expands that menu and triggers its callback"
written in the documentation here in the description of the MenuSelectedFcn.
For me this is a very annoying behavior - does anyone know a workaround of this ?

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!