It's strange that JScrollPane
doesn't have a method addAdjustmentListener()
. Yet adjustmentListener is said to be used with scrollbars. I want something to happen whenever the JScrollPane
is scrolled in either way. How to achieve such a thing?
A JScrollPane provides a scrollable view of a component. When screen real estate is limited, use a scroll pane to display a component that is large or one whose size can change dynamically. Other containers used to save screen space include split panes and tabbed panes.
A JScrollBar is a component and it doesn't handle its own events whereas a JScrollPane is a Container and it handles its own events and performs its own scrolling.
Instead of trying to listen for changes from the JScrollPane, get the viewport for that scroll pane add a change listener to it:
http://download.oracle.com/javase/6/docs/api/javax/swing/JViewport.html#addChangeListener(javax.swing.event.ChangeListener)
Why don't you get the actual scrollbars, and then add adjustment listeners to them? JScrollBar
has a method called addAdjustmentListener()
.
And you can use getVerticalScrollBar()
and getHorizontalScrollBar()
to get a JScrollBar
from a JScrollPane
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With