Reputation: 1110
I am using the uicontrol
command to have focus on my edit object. After this command, the string inside the uicontrol
is selected. How can I place the cursor after the last character ?
Here is my code.
H = figure;
E1 = uicontrol( 'Parent', H, 'Style', 'Edit', 'String', 'ABC', 'Units', 'Normalized', 'Position', [0.1,0,0.1,0.1] );
T1 = uicontrol( 'Parent', H, 'Style', 'Text', 'String', 'ABC', 'Units', 'Normalized', 'Position', [0.2,0,0.1,0.1] );
uicontrol( E1 )
Upvotes: 0
Views: 118
Reputation: 23675
What you are attempting to do cannot be realized through pure Matlab code. You have to interact with the underlying Java components... and for this you require the non built-in function findjobj.
Here is an example:
len = numel(E1.String);
jEdit = findjobj(E1);
uicontrol(E1);
jEdit.setCaretPosition(len);
jEdit.setSelectionStart(len);
jEdit.setSelectionEnd(len);
Upvotes: 1