How to programmatically scroll down multiline edit box ?

4 views (last 30 days)
When writing in a multiline edit box I would like to get it scrolled down automatically. How can I do ?
  1 Comment
Jiro Doke
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.

Sign in to comment.

Accepted Answer

Walter Roberson
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...

More Answers (2)

Yair Altman
Yair Altman on 11 Apr 2011

谢文 刘
谢文 刘 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.

Categories

Find more on Interactive Control and Callbacks 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!