How can I set focus to a uifigure
after the focus is switched out to a different figure?
For uicontrol
, it is possible with set focus on one of its child elements. For example:
% create a new uicontrol text label
h = uicontrol('style','text','string','This is my figure');
% create a figure to switch the focus
figure;
% switch back
uicontrol(h)
However, for uifigure
, adopting a similar code only creates a new uifigure
.
Some code for you to try:
% 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(h)
% this creates an error as the first input argument must be a valid parent for uilabel
uilabel(lh)
Any idea, insight or contribution is appreciated.
Note your Matlab version should be at least 2016a, since this is when uifigure
is introduced.