Synchronize the scroll bars between 2 template canvases

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