2009-06-25 6 views

Répondre

6

j'ai pu confirmer les travaux suivants dans GWT 1.5 au moins:

final VerticalPanel vp = new VerticalPanel(); 
for (int i = 0; i < 40; i++) { 
    vp.add(new HTML("Oh oh")); 
} 
final HTML f = new HTML("END"); 
vp.add(f); 

final ScrollPanel panel = new ScrollPanel(vp); 
panel.setHeight("20em"); 
panel.addScrollListener(new ScrollListener() { 

    HTML end = f; 
    public void onScroll(Widget widget, int scrollLeft, int scrollTop) { 

     int finalPos = end.getAbsoluteTop() + end.getOffsetHeight(); 
     int panelPos = panel.getAbsoluteTop() + panel.getOffsetHeight(); 
     if (finalPos == panelPos) { 
      end = new HTML("MORE !!"); 
      vp.add(end); 
     } 

    } 
}); 

Notez les bits intéressants sont les calculs des positions.

8

Essayez quelque chose comme ceci:

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)); 
     } 
    } 
} 

Qu'est-ce que ce code fait: il crée un ScrollPanel et ajoute une scrollHandler à elle. Dans le ScrollHandler, la scrollheight est comparée à la hauteur du panneau et ajoute ensuite un autre enfant au panneau.

Je ne l'ai pas testé parce que j'écris ceci sur un netbook et que je n'ai pas d'IDE dessus.

+0

Merci Chris - Je suppose que l'astuce est alors à maintenant les hauteurs et quand déclencher des choses à ajouter au panneau etc. –

+0

Si vous ne connaissez pas la hauteur, vous pouvez appeler getOffsetHeight, mais alors vous devez savoir les décorations (bordures, marge, rembourrage) –

Questions connexes