如何在输入对话框中预设光标或选择默认答案 [英] How to pre-set cursor or selection for default answer in input dialog

查看:103
本文介绍了如何在输入对话框中预设光标或选择默认答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果使用inputdlg和默认答案创建了一个输入对话框,则它看起来像这样:

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.

这个问题实际上已经解决了,因为我发现对于我的特殊情况,有方便的功能,例如uigetfileuiputfile.但是我的问题的一般情况仍然无法解决,或者至少我还没有测试过Java方法.

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.

推荐答案

恐怕使用内置的inputdlg而不进行更改是不可能的. 至少没有为此提供隐藏"功能.

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

为此,您需要访问基础的Java TextField对象. 您可以将inputdlg复制到某个新位置,然后制作自己的版本.

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.

findjobj实用程序结合使用时,原则上存在所需的功能. http://www.mathworks .com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects 事情可能看起来像这样:

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

这篇关于如何在输入对话框中预设光标或选择默认答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆