How can I implement singleton behavior for a programmtically created GUI?
5 views (last 30 days)
Show older comments
I am creating a GUI programmatically. However I require the singleton GUI behavior for my project. (i.e. if the user tries to run a second instance of my program it only brings the current singleton into focus and does not destroy any objects).
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
The singleton behavior can be implemented by querying for the tag of the GUI under the root object. If the GUI has been launched , the GUI will be a child of the root object. If the GUI has not been launched, it will not be found and the GUI can be launched.
The following code demonstrates this
function my_gui()
%Search if the figure exists
h = findall(0,'tag','my_gui');
if (isempty(h))
%Launch the figure
figHandle = figure('tag','my_gui');
plot(rand(4,4));
set(figHandle,'handlevisibility','callback');
else
%Figure exists so bring Figure to the focus
figure(h);
end;
0 Comments
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!