Menu Bar in App Designer

조회 수: 23 (최근 30일)
René Lampert
René Lampert 2021년 11월 27일
댓글: René Lampert 2021년 12월 1일
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

채택된 답변

Srijith Kasaragod
Srijith Kasaragod 2021년 12월 1일
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
René Lampert
René Lampert 2021년 12월 1일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

René Lampert
René Lampert 2021년 11월 30일
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 ?

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by