uicontrol edit field .String doesn't visually update from KeyReleaseFcn unless a breakpoint is set
Show older comments
Hello!
I'm forcing uppercase text in a classic uicontrol edit field as the user types (need figure, not uifigure — too slow to create for my use case).
function minimal_example
fig = figure('MenuBar','none','NumberTitle','off');
edit_field = uicontrol('Parent', fig, 'Style', 'edit', ...
'Position', [50 50 150 30], ...
'KeyReleaseFcn', @forceUpper);
function forceUpper(hObject, ~)
upperStr = upper(hObject.String);
if ~strcmp(hObject.String, upperStr)
hObject.String = upperStr;
end
end
end
Expected: typing lowercase letters shows uppercase immediately.
Actual: Nothing visually updates — although edit_field.String is correctly 'ABC' internally when checked afterward. If I add any breakpoint inside forceUpper, it suddenly works correctly.
This looks like a repaint race condition: .String updates internally, but the widget doesn't redraw before control returns to the event queue.
Im using R2024
Do you have a fix for this? or is there another way to create the GUI faster than uifigure but in a way that it updates the string?
Accepted Answer
More Answers (0)
Categories
Find more on Maintain or Transition figure-Based 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!