Template Repeater Scroll With Power Table Objects

I played around with this, and using the Power Table's initialize extension function and mouseExited event handler, I was able to add a listener like @PGriffith suggested while simultaneously controlling the scroll bar policy of the individual tables that were not in focus.

Here is the result:

Here is the code for the mouseExited event handler:

from javax.swing import SwingUtilities, JScrollPane 
tableScrollbar = event.source.getComponent(2)
tableScrollPane = SwingUtilities.getAncestorOfClass(JScrollPane, tableScrollbar)
tableScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER)

Here is the code for the initialize extension function:

	from java.awt.event import MouseWheelEvent, MouseWheelListener
	from javax.swing import SwingUtilities, JScrollPane 
	from java.awt import Point
	source = self
	tableScrollbar = source.getComponent(2)
	tableScrollPane = SwingUtilities.getAncestorOfClass(JScrollPane, tableScrollbar)
	tableScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER)
	repeater = source.parent.parent.parent.parent.parent
	repeaterScrollBar = repeater.getComponents()[1].getComponents()[2]
	repeaterScrollPane = SwingUtilities.getAncestorOfClass(JScrollPane, repeaterScrollBar)
	repeaterScrollPane.getVerticalScrollBar().setUnitIncrement(10)
	repeaterScrollPane.getVerticalScrollBar().setBlockIncrement(10)
	class DebugMouseWheelListener(MouseWheelListener):
		def mouseWheelMoved(self, event):
			scrollAmount = event.getUnitsToScroll()
			currentRepeaterPosition = repeaterScrollPane.getViewport().getViewPosition().y
			currentTablePosition = tableScrollPane.getViewport().getViewPosition().y
			if (currentRepeaterPosition + (scrollAmount)) > 0 and not source.table.isFocusOwner():
				tableScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER)
				repeaterScrollPane.getViewport().setViewPosition(Point(0,(currentRepeaterPosition + (scrollAmount*10))))
			else:
				tableScrollPane.setVerticalScrollBarPolicy(JScrollPane. VERTICAL_SCROLLBAR_AS_NEEDED)
	self.addMouseWheelListener(DebugMouseWheelListener())
3 Likes