In MATLAB 6.0 (R12) why does the callback of an edit uicontrol not fire when I change text in the field and then go to a menu and select an item on that menu?

2 views (last 30 days)
The documentation on Handle Graphics Object Properties under Uicontrol has the following description for the Callback property:
To execute the callback routine for an editable text control, type in the desired text, then either:
  • Move the focus off the object (click the mouse someplace else in the GUI),
  • For a single line editable text box, press Return, or
  • For a multiline editable text box, press Ctl-Return.
However, I try the following code:
uicontrol('Style','edit',...
'units','characters',...
'callback','disp(''Edit Box Callback'')',...
'position',[10 10 50 2])
u(1) = uimenu('parent',gcf,...
'Label','top Level')
u(2) = uimenu('parent',u(1),...
'Label','First Item');
u(3) = uimenu('parent',u(1),...
'Label','Second Item',...
'callback','disp(''Menu Callback'')');
Now I type in the edit field and then click the second menu item. The callback of the menu executes but up to this point the callback for the edit box has not executed.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 6 Jul 2010
This bug has been fixed for Release 14 (R14). For previous releases, please read below for any possible workarounds:
This is the expected behavior for MATLAB under Windows. On UNIX systems, clicking on the menubar of the figure window causes the edit text callback to execute. However, on Windows systems, if an editable text box has focus, clicking on the menu bar does not cause the editable text callback routine to execute. This allows you to select text in an editable text box, and then choose copy/cut/paste routines from the menubar without executing the callback.
This behavior is consistent with the respective platform conventions. Clicking on other components or the background of the GUI executes the callback.
This issue has been forwarded to our documentation team to be clarified in future documentation.
If you would like for your editable text box's callback to execute when you click on a UIMENU, then you can use the following as a workaround:
% In the callback to the UIMENU, begin with the following lines of code:
figure(gcbf); % Changes the focus to the figure so that the editable text box loses focus
drawnow; % Forces the editable text box to update and fires the callback immediately
% Subsequently, you can now access the editable text box's string:
% This example assumes that the handle to the text box is stored in "handles.edit"
get(handles.edit, 'string') % returns the new string.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!