Edit box 'keypressfcn' does not refresh the Edit box, unless I am debugging the callback function
Afficher commentaires plus anciens
I have the following code (I want to avoid non numeric input in the edit box):
hfig=figure(1);
hhh = uicontrol(hfig...
,'Style','edit'...
,'Position',[10 310 150 40]...
,'HorizontalAlignment', 'right'...
,'KeyPressFcn',@keyPressCallback...
);
function keyPressCallback(source,eventdata)
switch eventdata.Key
case 'return'
box_getnumber(source);
end
end
function box_getnumber(hhh)
nummer=get(hhh,'String');
if ~isempty(nummer)
nummer=cell2mat(regexp(nummer,'[0-9e.-+]','match'));
if ~isempty(nummer)
nummer=str2double(nummer);
hhh.String=num2str(nummer,'%15.5g');
end
end
end
This code does not update the Edit box content. If I put a breakpoint anywhere in the two functions then I continue the run, the Edit box refreshes.
What is wrong in the code? (I have tried 'drawnow', it does not work!)
Csaba
Réponse acceptée
Plus de réponses (1)
Sahithi Kanumarlapudi
le 27 Août 2020
Hi Csaba,
I have brought this issue to the notice of our developers. They will investigate the matter further.
And 'uieditfield'function could serve you as an alternative. The following code snippet is an example to create an edit field which will throw a warning on entering non-numeric data.
f = uifigure()
e = uieditfield(f,'numeric')
Hope this helps!
1 commentaire
Catégories
En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!