Why does the callback for the edit box in my GUI execute twice in MATLAB 7.0.1 (R14SP1)?

1 view (last 30 days)
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
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

More Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Products


Release

R14SP1

Community Treasure Hunt

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

Start Hunting!