How to set focus in UI figure?
6 views (last 30 days)
Show older comments
Dear colleagues
I am creating a GUI with multiple buttons. Normally, by default, pressing space bar equals clicking on the button which has the focus (usually last clicked button). In my app, space bar has, however, another function and I do not want the space bar to trigger any button. In my previous version I used figure instead of uifigure and I programatically set focus on an uicontrol of Text type in each button callback function. This way the clicked button lost focus because the focus was set on a non-clickable text and, therefore, pressing space bar did not trigger any button. The syntax for setting focus was uicontrol(uiCtr).
Now I want to use uifigure and associated uibutton and uilabel functions for creating the GUI. uilabel(uiLbl) does not work since it is trying to make a new label as a child of the uiLbl not just set focus on uiLbl.
How can I make sure that none of the buttons have focus? Is there any other way to prevent space bar from triggering the last clicked button?
2 Comments
Deepu S S
on 5 Jan 2022
% create a new uifigure h = uifigure('Name','This is my figure'); % create a new uilabel as a child of uifigure lh = uilabel(h) % create a figure to switch the focus figure; % this creates a new uifigure then switch back uifigure() uifigurepop(h); Your figure is now rendered topmost on the screen.
Answers (0)
See Also
Categories
Find more on Develop uifigure-Based Apps 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!