I am using ‘appdesigner’, I would like to programmatically scroll to the bottom of a TextArea, is this possible?

조회 수: 32 (최근 30일)
I am using ‘appdesigner’.
I would like to programmatically scroll to the bottom of a TextArea, is this possible?
My text area is being used a "console log".
Thanks, Gregg

답변 (4개)

Michael Corbett
Michael Corbett 2018년 10월 12일
To accomplish a scrolling text area, I did the following:
- Create the Text Area with 3 lines high (or as many as you'd like).
- Create a public consoleObj object using
properties (Access = public)
consoleObj
end
- On startup, write lines one and two (change to whatever appropriate):
app.consoleObj.line1 = 'Console Started';
app.consoleObj.line2 = 'System ready';
app.consoleObj.line3 = '';
app.ConsoleTextArea.Value = {app.consoleObj.line1;app.consoleObj.line2;app.consoleObj.line3};
- Wrote a function that would replace line1 with line2, line2 with line3, then add the new line3 and display:
methods (Access = public)
function writeConsoleLine(app,lineIn)
app.consoleObj.line1 = app.consoleObj.line2;
app.consoleObj.line2 = app.consoleObj.line3;
app.consoleObj.line3 = lineIn;
app.ConsoleTextArea.Value = {app.consoleObj.line1;app.consoleObj.line2;app.consoleObj.line3};
end
- Call the function to display the new text.
writeConsoleLine(app,'Pushbutton pressed');
  댓글 수: 3
Jan
Jan 2019년 2월 14일
@Marko: Please use flags only to inform admins and editors about content, which might conflict with the terms of use, like spam or rudeness. Thanks.
If this answer solves your problem, "accept" it instead of setting a flag.
Samuel Salinas
Samuel Salinas 2020년 6월 12일
I tried the same approach but the "app.ConsoleTextArea.Value" field demands a string scalar or charcater vector, not a cell.
How do I go around this?

댓글을 달려면 로그인하십시오.


Joshua Welsh
Joshua Welsh 2018년 4월 16일

Put your text into a ListBox instead of text area and then use the scroll function:

     scroll(app.ListBox, 'bottom')
  댓글 수: 3
Rayan Alkashgari
Rayan Alkashgari 2019년 3월 7일
This works in Matlab 2018b. Make sure to pause after adding an item then execute:
app.ListBox.scroll('bottom')
Cool_CZ
Cool_CZ 2019년 3월 25일
Thanks Rayan! That works for me(R2018b), just add "drawnow" before above command.

댓글을 달려면 로그인하십시오.


Han Geerligs
Han Geerligs 2017년 6월 9일
Hi Gregg,
I have the same question. Do you have any solution already?
regards, Han

Eric Sargent
Eric Sargent 2020년 12월 9일

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by