Auto "Scroll" to selected row in a Table Component

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?

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…

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

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

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

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.

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):

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

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

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

Gary

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

Thanks Jordan!
That’s perfect. :slight_smile:

1 Like

Hi @JordanCClark
your script is scrolling the text vertically

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

jTable.getCellRect(int row, int column, boolean includeSpacing)
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()

1 Like

@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

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

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

can you please help me on scripting part for this

This may be more what you’re looking for.

1 Like

thanks i will check it out