Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do make an infinite jscrollpane?

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.

like image 322
Pyrolistical Avatar asked Aug 31 '25 10:08

Pyrolistical


2 Answers

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!

like image 113
Bones Avatar answered Sep 03 '25 00:09

Bones


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).

like image 36
akf Avatar answered Sep 03 '25 00:09

akf