It shocks me that it doesn't behave this way because this describes the normal swing behavior that I'm used to seeing in Ignition.
Yes. It is possible to create a mouse wheel listener that provides the desired behavior and add it to the text area at initialization using the componentRunning
property change event.
Example:
# Written for the propertyChange event handler of the templatized text area component
if event.propertyName == 'componentRunning':
from java.awt import Point
from java.awt.event import MouseWheelListener
from javax.swing import JScrollPane, SwingUtilities
# Create a special mouse wheel listener for the templetized text area
class TextAreaMouseWheelListener(MouseWheelListener):
def mouseWheelMoved(self, event):
# Adjust the scroll pane position within the boundaries of the text area's viewport
newY = event.source.viewPosition.y + event.wheelRotation * event.scrollAmount
event.source.viewPosition = Point(event.source.viewPosition.x, min(maxY, max(minY, newY)))
# If the boudaries have been met or exceeded, move the parent scroll pane instead [if it exists]
if (newY <= minY or newY >= maxY) and parentScrollPane:
parentScrollPane.viewport.viewPosition = Point(parentScrollPane.viewport.viewPosition.x, parentScrollPane.viewport.viewPosition.y + event.wheelRotation * event.scrollAmount)
# Define the text area viewport, and attempt to get the repeater's scroll pane
viewport = event.source.viewport
parentScrollPane = SwingUtilities.getAncestorOfClass(JScrollPane, event.source)
# Define the boundaries of the viewport
minY = 0
maxY = viewport.view.size.height - viewport.size.height
# Add the TextAreaMouseWheelListener, but first,
# check to see if the listener is already present, so it doesn't get added twice
if 'TextAreaMouseWheelListener' not in [listener.__class__.__name__ for listener in viewport.mouseWheelListeners]:
viewport.addMouseWheelListener(TextAreaMouseWheelListener())