How can I implement singleton behavior for a programmtically created GUI?

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).

 采纳的回答

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 个)

类别

帮助中心File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by