Menu Bar in App Designer

20 ビュー (過去 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 Center および File ExchangeDevelop 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