3 Replies Latest reply: Sep 7, 2012 12:56 AM by StanislavL RSS

    Infinite (auto-extending) JScrollPane

      Does anyone know how to properly implement an infinite JScrollPane like e. g. in Visio?

      Example: When you scroll to the right, the scrollpane should auto-extend by 100 pixel. Same for all the other directions.

      Thank you for your help! :-)
        • 1. Re: Infinite (auto-extending) JScrollPane
          You can use JScrollBar's method public void addAdjustmentListener(AdjustmentListener l) and add listener to listgen scrolling events
          When rightmost position of the scroll is achived you increase preferred width of JScrollPane's content (+100 pixels).
          • 2. Re: Infinite (auto-extending) JScrollPane
            Thank you, I already did that, that was the easy part. The harder part is the negative coordinate-system. You have to extend top/left, adjust the viewport position, which invokes the AdjustmentListener and then you get into an endless loop, etc. I didn't want to invent everything again from scratch, that's why thought I'd ask first.
            • 3. Re: Infinite (auto-extending) JScrollPane
              For me the logic to avoid endless loop should be following.

              When user scrolls to the leftmost position (0) you increase width (+100 pixels) and move the scrollbar to 100 position. In the AdjustmentListener you check what's the curretn value. If it's bigger than 0 just skip the event. The same with rightmost.

              It should work.