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

 Akzeptierte Antwort

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;

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Hilfe-Center und File Exchange

Produkte

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by