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

21 ビュー (過去 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 件のコメント
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 件のコメント
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 日
As of R2020b uitextarea now supports scroll.
In this case you could use:
scroll(textArea, 'bottom')

カテゴリ

Find more on Entering Commands 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!

Translated by