Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I use GWT to create an infinite scroll panel?

Tags:

gwt

By infinite scrolling, I mean I initially load a few child widgets, and as the user scrolls down lazily load more to fill it out.

Any ideas appreciated.

(ideally would like something for GWT 1.6 and 1.5)

like image 569
Michael Neale Avatar asked Jun 25 '09 07:06

Michael Neale


1 Answers

Try something like this:

public static class InfiniteScrollPanel implements ScrollHandler {
    String text = "Lorem ipsum dolor sit amet, consectetuer...";
    ScrollPanel panel = new ScrollPanel(new HTML(text));
    int height = 200;
    int width = 200;

    public InfiniteScrollPanel() {
        panel.setHeight(height);
        panel.setWidth(width);
        panel.addScrollHandler(this);  
    }
    public void onScroll(ScrollEvent event) {
        if (panel.getScrollPosition == height) {
            panel.add(new HTML(text));
        }
    }
}

What this code does: it creates a ScrollPanel and adds a ScrollHandler to it. In the ScrollHandler the scrollheight gets compared to the height of the panel and it then adds another child to the panel.

I haven't tested it because I'm writing this on a netbook and don't have an IDE on it.

like image 99
Chris Boesing Avatar answered Nov 14 '22 23:11

Chris Boesing