How to programmatically scroll down multiline edit box ?
조회 수: 1 (최근 30일)
이전 댓글 표시
When writing in a multiline edit box I would like to get it scrolled down automatically. How can I do ?
댓글 수: 1
Jiro Doke
2011년 2월 21일
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.
채택된 답변
Walter Roberson
2011년 2월 21일
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
추가 답변 (2개)
Yair Altman
2011년 4월 11일
Answered in this article: http://undocumentedmatlab.com/blog/setting-line-position-in-edit-box-uicontrol/
Yair Altman
댓글 수: 0
谢文 刘
2022년 5월 13일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!