Filter löschen
Filter löschen

How to programmatically scroll down multiline edit box ?

9 Ansichten (letzte 30 Tage)
p fontaine
p fontaine am 21 Feb. 2011
Beantwortet: 谢文 刘 am 13 Mai 2022
When writing in a multiline edit box I would like to get it scrolled down automatically. How can I do ?
  1 Kommentar
Jiro Doke
Jiro Doke am 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Weitere Antworten (2)

Yair Altman
Yair Altman am 11 Apr. 2011

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

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by