Search code examples
javaswingscrollbarjscrollpane

Where is the viewport "connected to" the scrollbar in JScrollPane?


I may need to create my own JScrollPane subclass. I've looked at the JScrollPane and ScrollPaneLayout source and believe I understand how it works. However, I can't see where the scrollbar(s) (when present) are "connected to" the viewport. In other words, I was expecting to see the viewport listening to the scrollbar to determine the displayed view coordinates, but find nothing about that. Will someone explain and/or point to me to the code that is doing this?


Solution

  • The last thing I thought to examine were the listeners on the JScrollPane. Doing so led me to javax.swing.plaf.basic.BasicScrollPaneUI.Handler, which is where all the "wiring" happens. So that's the answer to the original question - but it points out an unfortunate reality: if I attempt to subclass JScrollPane to work as I intend, it seems unlikely that I'll be able to do so without breaking PLaF (with my current understanding of PLaF).

    Edit: I found this link to be helpful in understanding swing.plaf.*, although it's quite old: http://www.oracle.com/technetwork/java/architecture-142923.html