How to programmatically scroll down multiline edit box ?
1 view (last 30 days)
Show older comments
When writing in a multiline edit box I would like to get it scrolled down automatically. How can I do ?
1 Comment
Jiro Doke
on 21 Feb 2011
A multiline edit box WILL scroll down automatically if you keep entering text beyond the visible rows. It will scroll in order to show the current cursor location.
Are you asking how to scroll to a specific location? Then I think Walter's answer covers it.
Accepted Answer
Walter Roberson
on 21 Feb 2011
I seem to recall that Yair Altman has a way to do it by going in at the Java level. See his UndocumentedMatlab site .
There is no supported method of doing it.
Well, not that would be acceptable to most people. If you put the edit box inside of a uipanel and set the panel to clipping, you can set the Position of the edit box within the uipanel in order to scroll / pan the edit box. Getting this to work in concert with the scroll bars of the edit box is whole other problem...
0 Comments
More Answers (2)
Yair Altman
on 11 Apr 2011
Answered in this article: http://undocumentedmatlab.com/blog/setting-line-position-in-edit-box-uicontrol/
Yair Altman
0 Comments
谢文 刘
on 13 May 2022
If your original idea is to display the newest data you got on edit panel and not to delete the previous data, I think I have a solution with Yair Altman's methods.
Here is my code.
function SetToBottom(hObject,~)
set(hObject,'VerticalScrollBarPolicy',javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
hObject.getVerticalScrollBar.setValue(hObject.getVerticalScrollBar.getMaximum);
hObject.repaint;
%When edit box is created, function 'SetToBottom' is added into
%'AdjustmentValueChangedCallback' which is called when 'String' is changed
function receivetext_CreateFcn(hObject, ~, ~)
% hObject handle to receivetext (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
jhEdit = findjobj(hObject);
hjScrollPane = handle(jhEdit,'CallbackProperties');
set(hjScrollPane,'AdjustmentValueChangedCallback',@SetToBottom);
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
Forgive my grammatical mistakes.
0 Comments
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!