How to automatically scroll a textbox to end of line?
6 次查看(过去 30 天)
显示 更早的评论
Hi all,
I'm trying to code a calculator, which has an inactive (non-editable) textbox used for display of the input. Is there a way to automatically scroll the textbox to the end when the input gets longer than the width of the textbox? (If it's impossible in matlab maybe there's some workaround in java?)
Thanks!
Niko
0 个评论
采纳的回答
Geoff Hayes
2014-9-13
Niko - if you go to the MATLAB File Exchange and download the submission findjobj and save this file somewhere in your MATLAB search path, then you can update your GUI with the following two lines of code that will set the caret to the end of the line in your edit box so that it creates the appearance of automatically scrolling to the end
% assume that the text box that has been updated with the user input is named
% text1
% after text1 has been updated, move the caret to the end of the line
jhText1 = findjobj(handles.text1);
jhText1.setCaretPosition(jhText1.getDocument.getLength);
I tried out the following by creating a simple GUI using GUIDE. (If you created your GUI in a different manner, then you will just have to replace handles.text1 with the handle to your non-editable text box.
The above worked in my version of MATLAB R2014a on OS X 10.8.5.
4 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Install Products 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!