So it works, but there are a couple of odd little behaviors with it.
First off, if the mouse cursor ends up on the border of the TextArea, the scrolling behavior stops like it did before. Moving it one pixel into a TextArea allows it to work again. I'm guessing this is due to the border not being part of the component that receives the listener, but if that's the case, why doesn't the default page scrolling take over, then?
Secondly, it allows you to scroll the page up beyond the normal extents of the parent window, but only while over a text area, and only when scrolling is already enabled on the parent. If scrolling is not required due to page length, this does not happen. So over a text area, the top of the page does not stop at the top of the viewport, but will keep going down until the mouse exits the text area (moving the mouse to stay in the text area will keep going until there are no more text areas that you can mouse over), leaving the area blank as the top of the page moves down. The bottom of the scrollable area acts as expected, stopping at the bottom of the viewable area.
To fix the second odd behavior, I simply did a check to see if the Y scrolling went negative, and if it did, set it to 0 instead:
if (newY <= minY or newY >= maxY) and parentScrollPane:
scrollY = parentScrollPane.viewport.viewPosition.y + event.wheelRotation * event.scrollAmount
scrlPnt = Point(parentScrollPane.viewport.viewPosition.x, 0 if scrollY < 0 else scrollY)
parentScrollPane.viewport.viewPosition = scrlPnt
Just used an in-line if statement to keep it a little cleaner (and broke up the line for easier reading without side-scrolling).
I'm still stumped on the first behavior... Any ideas here? The only thing separating my text areas is a basic Line Border, no padding. I'm guessing the window still considers it part of the TextArea, but the listener does not extend beyond the viewport while the border does. Not sure how to extend a listener to a border, though...
Edit: One other behavior results from a difference in viewports. I have this code to speed up the main viewport scrolling:
def fixScrollSpeedTC(scrollableObj,speedValue):
components = scrollableObj.getComponents()
# find the embedded JideScrollPane$ScrollBar component
for component in components:
if str(type(component)) == "<type 'javax.swing.JScrollPane$ScrollBar'>":
if component.getOrientation() == 1:
component.setUnitIncrement(speedValue)
called after the construction of the main window and canvas with:
tc = system.gui.getParentWindow(event).getComponentForPath('Root Container.MainCanvas').getComponents()[0].getComponents()[0].getComponents()[2]
UniversalScripts.QoLScripts.fixScrollSpeedTC(tc,20)
But, obviously, this only affects the main window. Scrolling via the text area reverts to the slow 1-pixel scroll speed. I'm working on a way to "inherit" the main window's scroll speed rather than running the function on each individual text area, but if anyone finds a way to do that before I figure it out (if I can figure it out...), feel free to post it!
Edit2:
Was able to fix the scroll speed by adding the line:
scrlSpd = parentScrollPane.getComponents()[1].getUnitIncrement()
after where parentScrollPane
was defined, then inside the listener I changed the one line:
scrollY = parentScrollPane.viewport.viewPosition.y + event.wheelRotation * event.scrollAmount
to replace event.scrollAmount
with scrlSpd
. This way it inherits the parent window's scroll speed automatically, so I could set additional windows to different speeds, if I want.
Still stuck on the issue of not scrolling if the mouse is over one of the text areas' borders...