Synchronize the scroll of two data table contents together and ChangeListener

Hi all,

I have two tables which i would like to scroll synchronously.
I am using pturmel’s example (Freeze table column), and everything is working fine.
But I would like add some point to stop that ChangeListener and break synchronous scrolling two tables. Not sure how to do this. There is removeChangeListener() but i did not figure out how to use it.
Also, where can be found some details regarding viewport, especially for Table Component (table.viewport)?

Any help is appreciated, thanks!

You have to pass the listener you want to remove to the removeChangeListener() method. Which means you need to save it somewhere persistent. A client property of the component is probably the best place.

Thank you ptumel.

I tried client property. I added myScrollEvent to Button_1, and save it as myClientProperty_1, and then use another Button_2, get myClentProperty_1, print myScrollProperty_1 (<function myScrollEvent at 0x2>), but when i try to remove change listener “tblT22.viewport.removeChangeListener(myScrollEvent)”, nothing happens. Change listener is still active and both table are still scroll synchronously.
What i am doing wrong?

Ah, I think you’ll actually have to subclass the ChangeListener interface. I think that happens under the hood if you just add a callable, so the callable isn’t really the ChangeListener. If you subclass it, jython shouldn’t transform it automagically.

Thank you ptumel.
It works now. (had to search a little bit about sub-interfaces of EventListener)

2 Likes

Care to share the example for the community…?

hi zxcslo, here is what is use for testing synchronize the scroll of two tables:

tblT22 = event.source.parent.getComponent(‘Table 22’)
tblT12 = event.source.parent.getComponent(‘Table 12’)

class myListener(ChangeListener):
def stateChange(self, e):
scrollBarMain = tblT22.getHorizontalScrollBar()
scrollBarTop = tblT12.getHorizontalScrollBar()
scrollBarTop.setValue(scrollBarMain.getValue())

#to add ChangeListener
tblT22.viewport.addChangeListener(myListener())

#to remove ChangeListener
mls = tblT22.viewport.getChangeListeners()
for m in mls:
tblT22.viewport.removeChangeListener(m)

1 Like