how do i make a full text area scroll up when i add more text?

조회 수: 64 (최근 30일)
steve draving
steve draving 2017년 8월 1일
댓글: Matthew Pelmear 2021년 6월 17일
i designed a gui for running automated tests using App Designer. it writes messages to a text area. after the text area fills up, it continues add the text to the bottom of the text array and adds a scroll bar on the right of the text area. all new text is added off-screen, below the bottom of the displayed text area and you have manually scroll to see any new messages. how do I make it automatically scroll, so that you always see the new messages without have to keep scrolling it manually?

채택된 답변

Sven Kneer
Sven Kneer 2019년 4월 3일
편집: Sven Kneer 2019년 4월 3일
Scrolling to the latest Line is a basic feature for a "TextArea" Component. I dont want to use workarounds with Listboxes. Please Mathworks, fix this little important Issue!
  댓글 수: 1
steve draving
steve draving 2019년 4월 3일
I agree. Fixing the problem would save other people grief in the future. It's the right thing to do.

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

추가 답변 (4개)

Eric Sargent
Eric Sargent 2020년 12월 9일
편집: Eric Sargent 2020년 12월 9일
As of R2020b uitextarea now supports scroll.
In this case you could use:
scroll(textArea, 'bottom')
  댓글 수: 1
Matthew Pelmear
Matthew Pelmear 2021년 6월 17일
This is nice in theory, but I had to add an extra newline to my textarea every time it's updated in order to ensure that the text will always be shown after calling scroll(). (It doesn't acually scroll all the way to the bottom for me, at least in linux.) R2021a.

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


Ted Shultz
Ted Shultz 2018년 6월 4일
I had the exact same issue. My crude work around was to add the new text to the start rather than the end of the text block. As new lines are added (now to the top) they remain visible as the scroll bar stays at the top and the older entries go down. I maintained two separate text objects, one (added to the bottom) for saving a text file, and one added to the top for displaying in the app designer window. Because all my events include a timestamp, it is not as bad as you may think. BUT yes, I completely agree with the implied premise of this question, of "can I set scroll = 100". I also would have liked this feature.
  댓글 수: 3
Michael
Michael 2019년 6월 7일
I'd like to just add another request to make the scroll position a property of the text area object. I'd also like to suggest an autoscroll to top, or autoscroll to bottom option.

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


Walter Roberson
Walter Roberson 2017년 8월 1일
I have not looked at this using app designer. If you were doing it outside of app designer you would have two choices:
1) go in at the Java level to adjust the properties of the Java swing object; or
2) put the text area inside a uipanel that is inside a second uipanel, and as you add text, keep making the text area larger so that it does not create scroll bars, and set the position of the inner uipanel so that the bottom of it is visible inside the outer uipanel. The outer uipanel works like a frame allowing only a fixed size of the inner panel to be visible.
  댓글 수: 2
steve draving
steve draving 2017년 8월 4일
Thanks Walter, but I'm stuck with App Designer. I can't grow the text area and I do need the scroll bar.
Walter Roberson
Walter Roberson 2017년 8월 4일
The design I outlined still allows for a scroll bar: the scroll bar would be put into the outer uipanel and it would control the position of the inner uipanel compared to the outer uipanel.
The reason I mentioned "so that it does not create scroll bars" is that unless you go into the java level, there is no external control over what portion of the uicontrol style text that is visible, so to be able to keep the bottom of the text area visible you have to keep the text area large enough to not create scroll bars -- but you can put a window frame on top of that large text area and move the text area relative to the window frame.
A couple of us have implemented this design; it is not the most pleasant of designs but it it is not horrible either.
However, I see that as yet app designer has no support for uicontrol, so you cannot do the above directly in app designer.
On the other hand, app designer does support uipanel(), and uitextarea(), and uislider(), so you might be able to achieve the same effect.

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


Mark Myong-Sik Otero
Mark Myong-Sik Otero 2019년 9월 9일
Hi there's an easy workaround that I implemented:
% Append to Text Area
msg = 'Hello World';
% Where app.taLog is a TextArea component
app.taLog.Value = [msg;app.taLog.Value];
  댓글 수: 2
steve draving
steve draving 2019년 9월 11일
This does display the newest entry, but the list is inverted, which is kind of weird. The ListBox is still best solution I've seen.
Mark Myong-Sik Otero
Mark Myong-Sik Otero 2019년 10월 8일
yes, that's correct. we're using the text area like a log so for our use case it works. but, i can see how the inversion could be unconventional when not used the way we use it.

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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by