stop bringing GUI to front
7 次查看(过去 30 天)
显示 更早的评论
Hi,
I actually have 2 GUIs. One open in the front and another one running in the background. The GUI in the background shows an axes which displays a text that is rebuilt periodically. Every rebuild brings the GUI to front. How can I turn this off?
0 个评论
采纳的回答
Jan
2013-9-20
A figure is moved to the front if it is explicitly requested to do so. Perhaps there is a figure(figHandle); axes(axesH) in your code, which move the figure to front and code to activate the wanted axes. Then text() writes to the specified axes, but the lifting of the figure is not useful in your case. A solution would be then:
text(0.5, 0.5, 'Hello', 'Parent', axesH)
Specifying the parent cares for writing to the wanted axes also, but without moving the figure to the front.
So please check your code e.g. by using the debugger until you find the command, which causes the activation of the figure. Then remove this command and replace it accordingly.
0 个评论
更多回答(1 个)
Sean de Wolski
2013-9-20
编辑:Sean de Wolski
2013-9-20
Hi Adrian,
You have to use low level plotting functionality to set the properties of graphics objects (i.e. the text) that already exist rather than creating new ones.
I did this in an example here for changing the figure settings, you'll need to do the same for text.
If you want a small example, I could create it for you.
More: Example
function changeTextInBackground
%Some strings to cycle through
strings = {'Hello World';...
'Happy Friday';...
'Oktoberfest is nearly here';...
'The Patriots are still 2-0!';...
'And the Ravens aren''t.'};
%Background figure
hFig1 = figure;
set(hFig1,'units','normalized');
plot(1:10);
%We create the text box here, only once
hText = text(5,5,'Initializing...');
%Build the foreground figure
hFig2 = figure;
surf(peaks);
% Timer will change text every second
T = timer('Period',1,... %period
'ExecutionMode','fixedRate',... %{singleShot,fixedRate,fixedSpacing,fixedDelay}
'BusyMode','drop',... %{drop, error, queue}
'TasksToExecute',200,...
'StartDelay',0,...
'TimerFcn',@changeText,...
'StartFcn',[],...
'StopFcn',[],...
'ErrorFcn',[]);
ii = 0; %index for cycling through strings
start(T);
function changeText(~,~)
% increment location
ii = ii+1; %Move the figure
%This is the key line!!! hText already exists, we're just updating
%it
set(hText,'String',strings{ii});
drawnow; %force update
%Reset
if ii == numel(strings)
ii = 0;
end
end
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!