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

有些话、适合烂在心里 提交于 2019-12-10 13:56:01

问题


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

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

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.


回答1:


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);


来源:https://stackoverflow.com/questions/19399701/how-to-pre-set-cursor-or-selection-for-default-answer-in-input-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!