how to close a waitbar under R2014b ?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Denis
am 7 Jan. 2015
Kommentiert: Titus Edelhofer
am 7 Jan. 2015
I have created a waitbar as follows:
h = waitbar(0,'1','Name','Approximating pi...',...
'CreateCancelBtn',...
'setappdata(gcbf,''canceling'',1)');
To kill this waitbar, we have to use delete(h) instead of close(h).
The problem is that during the development and testings, it is possible that the h variable is cleared or overwritten. Then the waitbar is still present but the handle is lost. In that case, how can I close the waitbar? Of course, clicking the closing X button does not work.
Thanks for your support.
0 Kommentare
Akzeptierte Antwort
David Sanchez
am 7 Jan. 2015
From documentation:
You should call delete to remove a wait bar when you give it a CloseRequestFcn, as in the preceding code; calling close does not close it, and makes its Cancel and Close Window buttons unresponsive. This happens because the figure's CloseRequestFcn recursively calls itself. In such a situation you must forcibly remove the wait bar, for example like this:
set(0,'ShowHiddenHandles','on')
delete(get(0,'Children'))
However, as issuing these commands will delete all open figures—not just the wait bar—it is best never to use close in a CloseRequestFcn to close a window.
0 Kommentare
Weitere Antworten (2)
Adam
am 7 Jan. 2015
Bearbeitet: Adam
am 7 Jan. 2015
hFigures = allchild( groot );
will give you the handles of all figures from which you can find the waitbar as having a tag 'TMWWaitbar' if you didn't set a different tag yourself or obviously the tag you set if you did.
Then you can get it's handle from that list (hFigures will be an array of handles if you have more figures than just the waitbar) and call delete on it as normal. e.g.
hWaitbar = hFigures( arrayfun( @(h) strcmp( h.Tag, 'TMWWaitbar' ), hFigures ) );
delete( hWaitbar );
0 Kommentare
Denis
am 7 Jan. 2015
1 Kommentar
Titus Edelhofer
am 7 Jan. 2015
Hi Denis,
you should mark the question then as answered, although in this case you have to choose between two equally valid answers ;-).
Titus
Siehe auch
Kategorien
Mehr zu Dialog Boxes finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!