Synchronize the scroll bars between 2 template canvases

I'm trying to synchronize the scroll bars between 2 template canvases. I found a few relevant post and got to this point of experimenting however instead of setting the scroll bar position on my template canvas it sets the position of the scroll bar in the designer. When I run a client it sets nothing. It does the same thing if I change the object reference to: "event.source", "event.source.parent", "event.source.parent.parent". All work to set the designer scroll bar position.

Why is it not setting the object of interest?

from javax.swing import SwingUtilities
from javax.swing import JScrollPane

event.source.parent.getComponent('Group 1').getComponent('Template Canvas 2'))
scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane, event.source)

scrollPane.getHorizontalScrollBar().setValue(200)

Once I get past this basic attempt to set the scroll position, I hope to further develop this to read the position of one template canvas and set the other to the same. The code will live in InternalFrameOpened so that is fires every time the scroll bar is moved similar to this post:

http://forum.inductiveautomation.com/t/freeze-table-column/1621/10

I tried to use a simplified version of the code in the post I linked because the objects are referenced differently but I get the error: "object has no attribute 'getVerticalScrollBar' when used on my template canvas. I then tried it on a table like the post and it worked. So can I not access the same properties of a template canvas? Is there another way to set the scroll bar position of a template canvas?

#singleColumnTable = event.source.parent.getComponent('Group 1').getComponent('Template Canvas 1') # doesn't work
singleColumnTable = event.source.parent.getComponent('Table') # this works!
scrollBarSingleColumn = singleColumnTable.getVerticalScrollBar()
scrollBarSingleColumn.setValue(200)

I figured it out thanks to another post:
[Scroll bar is slow]

I needed to add “.getComponents()[2].getComponents()[0]” to the end of how I was referencing the components.

I placed this script in the window’s internalFrameOpened event handler and now my my template canvas scroll position tracks with another one.

from javax.swing import SwingUtilities
from javax.swing import JScrollPane

mainPane = SwingUtilities.getAncestorOfClass(JScrollPane, system.gui.getParentWindow(event).getComponentForPath('Root Container.Group 1.Template Canvas 1').getComponents()[2].getComponents()[0])
 
#def myScrollEvent(event = event, mainTable = tbl):
def myScrollEvent(event = event, mainPane = mainPane):	
	mainPanePosition = mainPane.getHorizontalScrollBar().getValue()
	headerPane = SwingUtilities.getAncestorOfClass(JScrollPane, system.gui.getParentWindow(event).getComponentForPath('Root Container.Group 1.Template Canvas 2').getComponents()[2].getComponents()[0])
	headerPane.getHorizontalScrollBar().setValue(mainPanePosition)
mainPane.viewport.addChangeListener(myScrollEvent)
1 Like