Stop Figure from taking Focus!!

7 次查看(过去 30 天)
I have created a function that repeatedly display a uitable (in a figure) that is looped every 10 seconds using a timer object. TheI global TASK variable in the function is continually being changed by a main function (not shown). The function displays information about tasks being performed and who (in a group) is performing what tasks. TASK is a global structure variable in the main program's data, that continually changes (what this function is built to display).
My question: How do I keep figure(2) from taking focus every time it loops??? I just want it to update in the background, and not pop up evey time or make my computer switch window to the figure! Seems simple. I'v tried two examples, listed below my function. The first is closest to what i want to happen, but havnt figured out how to adapt it to mine. Please help! Thank you!
%DISPLAY FUNCTION for main program:
function displayCurrent()
global a; global TASK;
if a==0
return; %If program has ended, stop updating the Display
end
%Create and Display Table (OUTPUT):
memberNames = {TASK(1).name,TASK(2).name,TASK(3).name}
tasktime = {TASK(1).hh_mm_ss,TASK(2).hh_mm_ss,TASK(3).hh_mm_ss};
memberIDs = {num2str(TASK(1).grpTsk_members), num2str(TASK(2).grpTsk_members), num2str(TASK(3).grpTsk_members)};
tasks = {TASK(1).title, TASK(2).title, TASK(3).title};
T = table(memberNames', tasktime', memberIDs', 'RowNames', tasks');
T.Properties.Description = 'DAILY TASK LIST';
T.Properties.VariableNames = {'AllMembers' 'TaskTime' 'CurrentIDs'};
%sfigure(figure(2)) %Does not work, or not using correctly
%h1 = figure(2);set(gcf,'Visible', 'off'); %Just makes figure go away compeltely...
figure(2) %STEALS FOCUS! HOW TO STOP????
UIT = uitable('Data',T{:,:},'ColumnName',T.Properties.VariableNames,...
'RowName',T.Properties.RowNames,'Units', 'Normalized', 'Position',[0, 0, 1, 1],'ColumnWidth', {150,100,70},'FontSize', 15);
%Looping timer-
t=timer; t.StartDelay = 10; t.TimerFcn = @(~,~) displayCurrent(); start(t)%Loops DISPLAY function
disp('');
end
I have tried many MATLAB resources. Here are a few I tried to implement with no luck:
1) The closest in effect to what want:
function example_focusin
T = timer('timerfcn',@updatePlot,'period',5,'executionmode','fixedrate','taskstoexecute',10);
figure; h = plot(rand(1,10));start(T);
function updatePlot(src,evt)
set(h,'ydata',rand(1,10));
end
end
AND
2) Couldnt get to work:
function h = sfigure(h)
% SFIGURE Create figure window (minus annoying focus-theft)... Usage is identical to figure. Daniel Eaton, 2005
if nargin>=1
if ishandle(h)
set(0, 'CurrentFigure', h);
else h = figure(h); end
else h = figure; end
end

采纳的回答

Walter Roberson
Walter Roberson 2018-12-26
Do not keep calling figure and making new uicontrol . create the objects ahead of time and update the appropriate properties .
  1 个评论
Matthew Cribb
Matthew Cribb 2018-12-26
编辑:Matthew Cribb 2019-5-21
Thank you!! You got me thinking in the right direction and I got it fixed. My main issue was as you said, calling the figure(2).
I initially had to call the figure because otherwise the uitable would update into a menu I had in my main program (really strange, but menus are outdated by lists so thats probably why). So i realized that you can specify what figure you want your uitable to be in, so I made a global figure (f1), put it in this function's UIT properties. Works as I want it to! Thanks!!
UIT = uitable(f1, 'Data',T{:,:},'ColumnName',T.Properties.VariableNames,...
'RowName',T.Properties.RowNames,'Units', 'Normalized', 'Position',[0, 0, 1, 1],'ColumnWidth', {150,100,70},'FontSize', 15);

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2018-12-26
  3 个评论
Walter Roberson
Walter Roberson 2020-2-17
You can record the handle returned by viscircles. It wil be an hggroup object, which has a Children property, and there will be one Chart Line object for each circle that is drawn. You can access those children and update their XData and YData properties.
LeChat
LeChat 2020-2-17
I answered you on the other discussion...

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by