Edit box 'keypressfcn' does not refresh the Edit box, unless I am debugging the callback function
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
Sahithi Kanumarlapudi
el 27 de Ag. de 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 comentario
Categorías
Más información sobre Interactive Control and Callbacks en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!