# Autoscroll Text Area

**URL:** <https://forum.inductiveautomation.com/t/autoscroll-text-area/2269>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [October 18, 2010, 1:28pm UTC](https://forum.inductiveautomation.com/t/autoscroll-text-area/2269 "2010-10-18T13:28:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![f\_jons](https://avatars.discourse-cdn.com/v4/letter/f/9fc29f/32.png) [@f\_jons](https://forum.inductiveautomation.com/u/f_jons)\
**Post date:** [October 18, 2010, 1:28pm UTC](https://forum.inductiveautomation.com/t/autoscroll-text-area/2269/1 "2010-10-18T13:28:24Z")

</div>

Is it possible to autoscroll the text area component to the end if more text is added to it? In Java, I used to be able to do:

```auto
JTextArea area = new JTextArea();
area.setCaretPosition( area.getDocument().getLength() );
```

Thanks!

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [October 20, 2010, 2:00am UTC](https://forum.inductiveautomation.com/t/autoscroll-text-area/2269/2 "2010-10-20T02:00:46Z")

</div>

Oh man, you already know how to do it in Java? You’re in luck - you can do all of that same stuff through Jython.

The only trick is that the “Text Area” component is actually a JScrollPane with a JTextArea in it.

So you’d do it like this:

`scrollPane = ... (grab the text area)
area = scrollPane.viewport.view
area.setCaretPosition(area.getDocument().getLength())`

---

<div class="post-metadata">

**Author:** ![f\_jons](https://avatars.discourse-cdn.com/v4/letter/f/9fc29f/32.png) [@f\_jons](https://forum.inductiveautomation.com/u/f_jons)\
**Post date:** [October 20, 2010, 1:37pm UTC](https://forum.inductiveautomation.com/t/autoscroll-text-area/2269/3 "2010-10-20T13:37:45Z")

</div>

I tried the code in a property change event for the text area so when new text would be added it would auto scroll.

```auto
if( event.propertyName == 'text' ):
    scrollPane = event.source
    area = scrollPane.viewport.view
    area.setCaretPosition( area.getDocument().getLength() )
```

It does not throw any errors, but does not scroll the text area. I know the script runs since I had inserted a simple print statement to check for sure. Ideas?

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [October 20, 2010, 3:34pm UTC](https://forum.inductiveautomation.com/t/autoscroll-text-area/2269/4 "2010-10-20T15:34:47Z")

</div>

Yeah, you probably need to wrap your code in an invokeLater call to ensure it occurs after the text area itself has actually responded to the new text being added.

`if( event.propertyName == 'text' ):
    def doScroll(scrollPane = event.source):
        area = scrollPane.viewport.view
        area.setCaretPosition( area.getDocument().getLength() )
    system.util.invokeLater(doScroll)`

---

<div class="post-metadata">

**Author:** ![f\_jons](https://avatars.discourse-cdn.com/v4/letter/f/9fc29f/32.png) [@f\_jons](https://forum.inductiveautomation.com/u/f_jons)\
**Post date:** [October 20, 2010, 3:46pm UTC](https://forum.inductiveautomation.com/t/autoscroll-text-area/2269/5 "2010-10-20T15:46:17Z")

</div>

Yep, worked perfectly. I keep forgetting about invokeLater.

Thanks!

---

<div class="post-metadata">

**Author:** ![Esn](https://avatars.discourse-cdn.com/v4/letter/e/91b2a8/32.png) [@Esn](https://forum.inductiveautomation.com/u/Esn)\
**Post date:** [July 14, 2022, 3:04pm UTC](https://forum.inductiveautomation.com/t/autoscroll-text-area/2269/6 "2022-07-14T15:04:14Z")

</div>

Hi,

Geez, hate to revive this ancient thread, but I want to auto scroll the text area component and the solution in this thread doesn’t work if the text property of the component is bound to a tag.  
It looks like the `event.propertyName == 'text'` doesn’t fire if the property is bound and then the auto scroll script doesn’t run.  
Is there a way to auto scroll the text area with the text property bound?

Thanks

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [July 14, 2022, 3:09pm UTC](https://forum.inductiveautomation.com/t/autoscroll-text-area/2269/7 "2022-07-14T15:09:43Z")

</div>

I didn’t read the entire thread, but maybe use a custom property instead and have the script on it write to `text`?

---

<div class="post-metadata">

**Author:** ![scottmwyant](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/scottmwyant/32/66369_2.png) [@scottmwyant](https://forum.inductiveautomation.com/u/scottmwyant)\
**Post date:** [September 22, 2022, 1:25pm UTC](https://forum.inductiveautomation.com/t/autoscroll-text-area/2269/8 "2022-09-22T13:25:53Z")

</div>

Working on implementing a log sink. I found another thread ([My Perspective Logger Component](https://forum.inductiveautomation.com/t/my-perspective-logger-component/38498/4)) with great sample code. It’s writing new lines to the top of the log rather than appending to the bottom, perhaps to avoid the need to keep the TextArea scrolled to the bottom.

Searching for how to do that, I’m not following the sample code shared in this thread. Anyone have a modern solution. This thread is 12yr old.
