This discussion is archived
3 Replies Latest reply: Sep 6, 2012 10:56 PM by StanislavL RSS

Infinite (auto-extending) JScrollPane

802349 Newbie
Currently Being Moderated
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
    StanislavL Pro
    Currently Being Moderated
    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
    802349 Newbie
    Currently Being Moderated
    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
    StanislavL Pro
    Currently Being Moderated
    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.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points