I've implemented drag scroll before, but what's the best way to go about creating an infinite scroll pane? Of course there won't be any scrollbars and I will implement drag scroll.
What I am trying to do is implement dynamic loading on an infinite surface.
EDIT
Of course it wouldn't actually be infinite. I am asking how to fake it.
You could do the following:
AdjustmentClass adj = new AdjustmentClass();
scrollPane.getHorizontalScrollBar().addAdjustmentListener(adj);
scrollPane.getVerticalScrollBar().addAdjustmentListener(adj);
And in your AdjustmentClass do the following:
public class AdjustmentClass implements AdjustmentListener {
public void adjustmentValueChanged(AdjustmentEvent adjustmentEvent) {
// Implement your custom code here
}
}
To get orientation of the event do:
adjustmentEvent.getAdjustable().getOrientation();
You find the orientation constants in:
AdjustmentEvent.UNIT_INCREMENT
AdjustmentEvent.BLOCK_INCREMENT
etc. etc.
To check if user is dragging the scroll-bar knob do:
adjustmentEvent.getValueIsAdjusting()
There are i few more, check the API for more info if you need.
Happy coding!
You could use JScrollPane.getViewport()
to get the JViewport
and add a ChangeListener
to it. The JViewport
will alert your listener when the size or, more importantly the position has changed. If the position has changed close to the edge of the JScrollPane
you can then resize the viewport (you will need to disregard the size-triggered change event).
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