How to set focus in UI figure?

5 views (last 30 days)
Jan Kudlacek
Jan Kudlacek on 5 Jan 2022
Commented: Jan Kudlacek on 5 Jan 2022
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
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.
Jan Kudlacek
Jan Kudlacek on 5 Jan 2022
Dear Deepu
Thank you for your response. I'm not sure you understood my question. It is not related to switching between figures. The question is how to programatically control focus on uibuttons within uifigure. Does creating one more figure help?

Sign in to comment.

Answers (0)

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!