I have found a workaround for the problem. If I change the focus from the edit field within the keypresscallback (i.e. to another edit field) then I come back to the original edit field the edit field refreshes.Here is the code:
hfig=figure(1);
hhh1 = uicontrol(hfig...
,'Style','edit'...
,'Position',[10 310 150 40]...
,'HorizontalAlignment', 'right'...
);
hhh2 = uicontrol(hfig...
,'Style','edit'...
,'Position',[10 210 150 40]...
,'HorizontalAlignment', 'right'...
);
hhh1.KeyPressFcn={@keyPressCallback,hhh2};
hhh2.KeyPressFcn={@keyPressCallback,hhh1};
function keyPressCallback(source,eventdata,hhh)
switch eventdata.Key
case 'return'
uicontrol(hhh);
uicontrol(source);
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