# Auto "Scroll" to selected row in a Table Component

**URL:** <https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011>\
**Category:** Ignition\
**Created:** [July 30, 2019, 6:23pm UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011 "2019-07-30T18:23:36Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [July 30, 2019, 6:23pm UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011/1 "2019-07-30T18:23:36Z")

</div>

I have a table that lists around 100 tanks and select data for each.  
On the screen I have a “Tank Search” box that can use either the tank id or a lot id.  
The functionality works to find and select the row for the found tank. What I would like to do is have the code show the selected row as well. As it stands now, the selected row may be above or below the currently displayed rows in the table.

Is there a way to have this logic “auto scroll” to display the found and selected row?

---

<div class="post-metadata">

**Author:** ![boyergary](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/boyergary/32/10316_2.png) [@boyergary](https://forum.inductiveautomation.com/u/boyergary)\
**Post date:** [October 4, 2019, 2:31pm UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011/2 "2019-10-04T14:31:42Z")

</div>

Bump. Looking for the same thing. I understand you can do it with a JTable, but I don’t know how to get a JTable from an Ignition table. At least, it doesn’t work with a List Table.

This would work if that getTable() reference worked…

```auto
	myJtable = list.getTable()
	rectangle = myJTable.getCellRect(rowNum,0,0)
	myJTable.scrollRectToVisible(rectangle)

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 4, 2019, 4:31pm UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011/3 "2019-10-04T16:31:42Z")

</div>

The JList is a bit more involved to retrieve. Try this in the property event script.

```python
if event.propertyName == "selectedIndex": 
	jList = event.source.getViewport().getComponent(0) 
	jList.ensureIndexIsVisible(event.newValue)

```

---

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [October 4, 2019, 4:58pm UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011/4 "2019-10-04T16:58:14Z")

</div>

Hey Jordan,  
I tried that and got an error, object has no ensureIndexIsVisible. When I do a dir on the jList object, that method is not in the results. I do see it in the java docs for the JList object though.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 4, 2019, 6:40pm UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011/5 "2019-10-04T18:40:00Z")

</div>

Let’s back up a sec. I may be confused on what you’re using. Correct me if I’m wrong, but:

@MikeAllgood is using a table  
@boyergary is using a list.

The first script I posted (above) is for a list.

For a table (also in the property change event):

```python
if event.propertyName == 'selectedRow':
	jTable = event.source.getTable()
	rectangle = jTable.getCellRect(event.newValue,0,0)
	jTable.scrollRectToVisible(rectangle)

```

---

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [October 4, 2019, 6:51pm UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011/6 "2019-10-04T18:51:36Z")

</div>

Ah, got cha!  
Yes, I’m using a table so guess I’m still in search of! 🙂  
Thanks!

---

<div class="post-metadata">

**Author:** ![boyergary](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/boyergary/32/10316_2.png) [@boyergary](https://forum.inductiveautomation.com/u/boyergary)\
**Post date:** [October 4, 2019, 7:02pm UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011/7 "2019-10-04T19:02:11Z")

</div>

Thanks much for the jList code, Jordan…that did the job for me!!

Gary

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 4, 2019, 7:19pm UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011/8 "2019-10-04T19:19:20Z")

</div>

The second bit of code I posted should work for you, Mike.

---

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [October 7, 2019, 2:06pm UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011/9 "2019-10-07T14:06:36Z")

</div>

> [@JordanCClark](#):
>
> jTable = event.source.getTable() rectangle = jTable.getCellRect(event.newValue,0,0) jTable.scrollRectToVisible(rectangle)

Thanks Jordan!  
That's perfect. 🙂

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [November 10, 2021, 8:43am UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011/10 "2021-11-10T08:43:10Z")

</div>

> [@JordanCClark](#):
>
> ```python
> if event.propertyName == 'selectedRow':
> jTable = event.source.getTable()
> rectangle = jTable.getCellRect(event.newValue,0,0)
> jTable.scrollRectToVisible(rectangle)
> 
> ```

Hi @JordanCClark  
your script is scrolling the text vertically

**i want to scroll the text horizontally ... what change i have to make in script?**

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 10, 2021, 9:25am UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011/11 "2021-11-10T09:25:54Z")

</div>

> [@JordanCClark](#):
>
> `rectangle = jTable.getCellRect(event.newValue,0,0)`

`jTable.getCellRect(int row, int column, boolean includeSpacing)`

> **[JTable (Java Platform SE 7 )](https://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html)**

so get the column you want to go to and change the second param in getCellRect()

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [November 11, 2021, 9:51am UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011/12 "2021-11-11T09:51:13Z")

</div>

@victordcq @JordanCClark

I just want the scroll message to appear based the day or time selection or particular time only… is there any idea to do that in scripting?

like i am just scheduling a time when that time comes only i want to show message on screen

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 11, 2021, 10:04am UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011/13 "2021-11-11T10:04:21Z")

</div>

I think there is some confusion here. Are you actually wanting a marquee type of display?

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [November 11, 2021, 10:32am UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011/14 "2021-11-11T10:32:36Z")

</div>

@JordanCClark yes exactly i want… giving some announcement to plant when ever required

can you please help me on scripting part for this

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 11, 2021, 11:12am UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011/15 "2021-11-11T11:12:14Z")

</div>

This may be more what you're looking for.

> [@How to make scrolling LCD Display (marquee)](https://forum.inductiveautomation.com/t/how-to-make-scrolling-lcd-display-marquee/3336/18):
>
> Here’s an update on Jordan’s marquee using system.gui.transform. It’s simpler and doesn’t need as many objects or bindings. Just set the root container’s time property to the length of time in milliseconds for the message to cross the container. It should cope with different length of container or message. Multiple messages is left as an exercise for the reader. [Marquee updated\_2017-09-07.proj](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/b73e3074b165b7b1024a73bf440946757624fca7.proj) (6.6 KB)

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [November 11, 2021, 11:34am UTC](https://forum.inductiveautomation.com/t/auto-scroll-to-selected-row-in-a-table-component/27011/16 "2021-11-11T11:34:28Z")

</div>

> [@JordanCClark](#):
>
> marquee type of display

thanks i will check it out
