没有 纯MATLAB 这样做的方式,但它是完全可能的,使用 undocummented 方法,操纵底层 java的 组件。
首先需要的是实用程序 findjobj 来自Matlab中心。您需要下载此函数并在MATLAB路径中访问它。此函数将检索MATLAB文本框底层的java对象的句柄。
findjobj
一旦你有权访问文本框的java方法,移动 caret 到文本末尾是微不足道的,你只需要调用其中一个组件方法: setCaretPosition(positionIndex) 。
caret
setCaretPosition(positionIndex)
一旦你有了这个功能 findjobj 在MATLAB路径中,只需在示例代码后添加此代码:
% Get the handle of the jave edit box jtxtBox = findjobj(txHandle) ; % Get the handle of the jave "panel" component jTxtPane = jtxtBox.getComponent(0).getComponent(0) ; % move the caret to the end of the text jTxtPane.setCaretPosition( numel(txt) );
et voila :-)