Stop Figure from taking Focus!!

28 views (last 30 days)
Matthew Cribb
Matthew Cribb on 25 Dec 2018
Commented: LeChat on 17 Feb 2020
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

Accepted Answer

Walter Roberson
Walter Roberson on 26 Dec 2018
Do not keep calling figure and making new uicontrol . create the objects ahead of time and update the appropriate properties .
  1 Comment
Matthew Cribb
Matthew Cribb on 26 Dec 2018
Edited: Matthew Cribb on 21 May 2019
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);

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 26 Dec 2018
  3 Comments
Walter Roberson
Walter Roberson on 17 Feb 2020
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 on 17 Feb 2020
I answered you on the other discussion...

Sign in to comment.

Categories

Find more on Graphics Performance 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!