matlab - 在 Matlab 文本窗口(uicontrol)上自动向下滚动
问题描述
我想使用 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组件。
首先需要的是findjobj
来自 Matlab 中心的实用程序。您需要下载此函数并在您的 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) );
等等瞧:-)
推荐阅读
- python - PyQt,文本光标
- c# - 上传文件并重新加载相同的局部视图
- sql - 用于查找未包含项目的 sql 查询
- amazon-web-services - AWS CLI restore-from-cluster-snapshot 在账户中找不到快照
- c - 二值化词嵌入压缩 (Tissier) // C-Binaries
- sql - 如何 SQL ORDER BY 但根据另一列保持结果聚集?
- sql - 我可以在子查询中有一个别名并运行这个别名的平均值吗?
- django - 使用 Allauth 和 rest-auth 在 Django REST 框架中配置 Apple 登录
- c++ - 当我将方法的定义与其声明分开时,为什么 MSVC 无法编译?
- css - Angular NgbDatepicker 部分隐藏