I finally had a chance to sit down and hammer away at this until I found a solution, so I'll post it here for anyone else who needs it. The fix is a simple two lines inserted before function deleteTextBox:
drawnow;
javaMethod('requestFocusInWindow',hTestField);
Alternatively, pause(0.001) can be substituted for drawnow if drawnow doesn't work. I've run into many issues where the latency in drawing a GUI element results in unexpected behavior, and this was yet another case of that.
2 Comments
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/588595-how-can-i-set-the-focus-to-a-gui-element-created-with-javacomponent#comment_995842
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/588595-how-can-i-set-the-focus-to-a-gui-element-created-with-javacomponent#comment_995842
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/588595-how-can-i-set-the-focus-to-a-gui-element-created-with-javacomponent#comment_995866
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/588595-how-can-i-set-the-focus-to-a-gui-element-created-with-javacomponent#comment_995866
Sign in to comment.