我想使用Matlab连续读取文件并在专用窗口中显示。所以我使用uicontrol
命令。它运行良好,但我希望每次更新内容时直接在内容结束时直接进行。这样做有什么解决方案吗?
MWE:
figHandle = figure('units','pixels',...
'position',[40 40 240 940],...
'menubar','none',...
'resize','off',...
'numbertitle','off',...
'name','window custom')
txHandle = uicontrol('style','edit',...
'units','pix',...
'position',[10 60 220 830],...
'backgroundcolor','w',...
'HorizontalAlign','left',...
'min',0,'max',10,...
'enable','inactive');
txt=repmat('t|',1,100000);
set(txHandle,'string',cat(1,get(txHandle,'string'),{txt}));
没有纯MATLAB方法这样做,但使用未填充的方法操作底层的java组件是完全可能的。
首先需要的是Matlab中心的实用程序findjobj
。您需要下载此函数并在MATLAB路径中访问它。此函数将检索MATLAB文本框底层的java对象的句柄。
一旦你可以访问文本框的java方法,将caret
移动到文本的末尾是微不足道的,你只需要调用一个组件方法:setCaretPosition(positionIndex)
。
在MATLAB路径中使用findjobj
函数后,只需在示例代码后添加此代码:
% 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) );
这里是:-)