How to disable matlab's figure menu's response to Alt button in R2016a?
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am writing callback for ALT+right click, but found that it works only 50% of times: one succeed and one failuter alternate, and I could see that the figure's menu bar is indicated by Alt for 50% of the time. I know that using Ctrl+Alt+right click is more stable, but this has been occupied for other purpose. I found that Alt single button is relayed OK to the callback when menu underline is triggered on, but for next Alt which triggered menu underline disappear, it is consumed and no longer trigger callback.
I tried:
jFrame = get(hFig, 'JavaFrame');
jFrame.setFocusableWindowState(false);
Undefined function 'setFocusableWindowState' for input arguments of type 'com.mathworks.hg.peer.HG2FigurePeer'.
0 commentaires
Réponses (1)
Aravind
le 9 Avr 2025
The reason the second press of the ALT button is not being recognized is because it triggers a default internal callback common to all windows, specifically for highlighting or not highlighting menu elements. This callback cannot be directly disabled.
As a workaround, you can disable the menu bar in the figure window whenever the ALT button is pressed. By disabling the menu bar, the internal callback for highlighting menu bar elements will not run. When the ALT button is released, you can enable the menu bar again. This way, you will be able to detect all ALT+Right clicks without missing any of them.
To disable the menu bar in the figure window, add the following code to the callback for pressing the ALT button:
set(fig, 'MenuBar', 'none');
Similarly, in the callback for releasing the ALT button, add the following code to restore the menu bar:
set(fig, 'MenuBar', 'figure');
For more information about turning the menu bar on and off, you can refer to this MATLAB answer: https://www.mathworks.com/matlabcentral/answers/99139-how-can-i-add-or-remove-the-menubar-or-toolbar-from-a-figure-in-matlab.
I hope this resolves your issue.
0 commentaires
Voir également
Catégories
En savoir plus sur Graphics Object Programming dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!