Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pre-set cursor or selection for default answer in input dialog

If one creates an inputdialog with inputdlg and a default answer, it looks like that:

enter image description here

Which callback command do I need to make it look like that?

enter image description here

The documentation is missing a lot here. It's a kind of "luxury service" for the customer ;) But I think it would be nice, if it's easy to implement.


This question is actually solved, as I found out that there are convenient functions like uigetfile and uiputfile for my particular case. But the general case of my questions remains unsolved or at least I haven't tested the java approach.

like image 266
Robert Seifert Avatar asked Oct 20 '22 22:10

Robert Seifert


1 Answers

I'm afraid using the builtin inputdlg without changes this is not possible. At least there's not 'hidden' feature allowing for this.

You'd need access to the underlying java TextField object for that purpose. You could copy inputdlg to some new place and make your own version of it.

In combination with the findjobj utility the desired functionality in principle exists. http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects Things could look like this then:

% create the edit-field:
h = uicontrol('style', 'edit',...);
% get the underlying java object
% this should be a javahandle to a JTextField
jtextfield = findjobj(h);
% set start/end of the selection as desired:
jtextfield.setSelectionStart(startPos);
jtextfield.setSelectionEnd(endPos);
like image 179
sebastian Avatar answered Oct 24 '22 01:10

sebastian