We have a vision Template Repeater with multiple Power Table objects. Users need to vertical scroll the template repeater to access the multiple power tables were data can viewed and manipulated.
Issue: when a user places the cursor in the middle of the template repeater and uses the scroll wheel, the scroll function will work up until the first power table appears below cursor. In order to keep scrolling the user needs to move cursor to edge of repeater and/or off the power table. This becomes a pain to the user as there are multiple power tables and they end up having to move the cursor frequently.
Question: Is there a way to disable scroll on an individual power table, or somehow prevent focus of the power table object while the main window is being scrolled through?
This is somewhat fundamental Java Swing behavior, so I'm not sure how much you will be able to work around it. You could potentially, in the power table(s), add a mouse scroll listener that consumes the scroll events on the table and 'forwards' them to the outer container. However, consuming the scroll events would then prevent you from being able to scroll within the table itself...
1 Like
Would it prevent scrolling capabilities altogether. i.e. mouse click drag + bar or scroll bar arrows?
You would still get the ability to scroll with other means; it would just block wheel events. Or you could dispatch your wheel events to both the table and the repeater, so you end up with "duplicate" scrolling sometimes.
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
Ah, that's pretty clever. I hadn't considered changing the scrollbar policy dynamically; that's a good workaround.
1 Like