Why does the callback for the edit box in my GUI execute twice in MATLAB 7.0.1 (R14SP1)?
1 view (last 30 days)
Show older comments
When I change the value of the 'String' property in the edit box callback function, the callback is executed a second time when the edit box loses focus.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
This is expected behavior. The callback event for an edit box is triggered by changing the String property and then changing the object focus.
To work around this issue, set a flag in the callback procedure that prevents the entire callback from being executed once the edit box loses focus.
For example:
function myedit_callback(hObject, eventdata, handles)
persistent myEditboxFlag
if isempty(myEdtiboxFlag)
myEditboxFlag = true;
end
if myEditboxFlag
%perform callback procedure
set(hObject, 'String', 'A new string')
myEditboxFlag = false;
else
myEditboxFlag = false;
end
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!