# Scroll two (or more ) tables with one scroolbar

**URL:** <https://forum.inductiveautomation.com/t/scroll-two-or-more-tables-with-one-scroolbar/20125>\
**Category:** General Discussion\
**Tags:** ignition79, scripting\
**Created:** [October 12, 2018, 3:19pm UTC](https://forum.inductiveautomation.com/t/scroll-two-or-more-tables-with-one-scroolbar/20125 "2018-10-12T15:19:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![c.bertulli](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@c.bertulli](https://forum.inductiveautomation.com/u/c.bertulli)\
**Post date:** [October 12, 2018, 3:19pm UTC](https://forum.inductiveautomation.com/t/scroll-two-or-more-tables-with-one-scroolbar/20125/1 "2018-10-12T15:19:51Z")

</div>

Hi all,

I wanted to be able to scroll ( vertically ) more tables based on just one scrollbar. I searched inside the forum but found nothing. Just some related posts. I took code from various posts and combined them together ( with no logic ) and I came up with the perfect result I wanted. Now, I am not a Java Expert ( I’m a Pythonian 🙂), I was wondering if someone could help me figure out how this bunch of code is working.

Here it is:  
I have 3 power tables called “Power Table”, “Power Table 1”, “Power Table 2”.  
Inside the **Mouse Clicked** event of the Power Table I have the following code:

```auto
foo = event.source.getVerticalScrollBar()
table_2 = event.source.parent.getComponent('Power Table 1')
table_2.setVerticalScrollBar(foo)
table_3 = event.source.parent.getComponent('Power Table 2')
table_3.setVerticalScrollBar(foo)

```

Inside the **Initialize** event of the Power Table I have the following code:

```auto
	from java.awt.event import MouseWheelEvent
	from java.awt.event import MouseWheelListener
	
	class DebugMouseWheelListener(MouseWheelListener):
		def mouseWheelMoved(self, event):
			print "Scroll wheel notches moved:", event.getWheelRotation()
			print "Units to scroll:", event.getUnitsToScroll()
			
	self.addMouseWheelListener(DebugMouseWheelListener())

```

No code inside the others table.

Here there’s a video showing the result [https:/uploads/iatesting/original/2X/a/a8545339f7e56263e556aafd258b1d205f4b40fb.mp4](https:/uploads/iatesting/original/2X/a/a8545339f7e56263e556aafd258b1d205f4b40fb.mp4)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 12, 2018, 3:30pm UTC](https://forum.inductiveautomation.com/t/scroll-two-or-more-tables-with-one-scroolbar/20125/2 "2018-10-12T15:30:40Z")

</div>

The code in the `initialize` event isn’t doing anything related to what you have here. The part that’s doing anything is the mouse click event, although that’s probably not the best event handler to put this in.

```auto
foo = event.source.getVerticalScrollBar()
table_2 = event.source.parent.getComponent('Power Table 1')
table_2.setVerticalScrollBar(foo)
table_3 = event.source.parent.getComponent('Power Table 2')
table_3.setVerticalScrollBar(foo)

```

You’re taking the internal scroll bar component from one table, and telling the other two power tables to use the same scroll bar. That’s _probably_ not the best/only way to do it, but if it’s working for you, by all means.

I would try putting the same code into the `initialize()` extension function (you can remove the other code there), and then replace `event.source` with `self`.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 12, 2018, 4:47pm UTC](https://forum.inductiveautomation.com/t/scroll-two-or-more-tables-with-one-scroolbar/20125/3 "2018-10-12T16:47:34Z")

</div>

I would add a ChangeListener to each table’s Viewport that would relay any desired operations to the other tables. And use mouseenter, mouseexit, and mousemove events to ensure only one table’s event are relayed at any given moment. The ChangeListener will get an event even if the scroll happens as a result of a non-mouse operation.

---

<div class="post-metadata">

**Author:** ![c.bertulli](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@c.bertulli](https://forum.inductiveautomation.com/u/c.bertulli)\
**Post date:** [October 15, 2018, 6:31am UTC](https://forum.inductiveautomation.com/t/scroll-two-or-more-tables-with-one-scroolbar/20125/4 "2018-10-15T06:31:42Z")

</div>

Thanks for the explanation! 🙂
