Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrolling to the top of a page in a gwt application

I've got a gwt application and I want to scroll to the top of a page using this method:

public static native void scrollTop() /*-{
  $wnd.scroll(0, 0);
}-*/;

The method is called in the onClick-method of a TreeNodeListenerAdapter:

new TreeNodeListenerAdapter() {
  @Override
  public void onClick(Node node, EventObject e) {
    scrollTop();
  }
}

This does not work and I don't know why. When I put an alert inside my method:

$wnd.alert("Treenode clicked");

I get to see the alert but the page is not scrolled. What am I missing here?

like image 535
xor_eq Avatar asked Jul 07 '10 12:07

xor_eq


1 Answers

If you want to scroll to the top of a page just do:

Window.scrollTo (0 ,0);

Just be sure that you are importing the correct package com.google.gwt.user.client.Window

like image 184
Andres Avatar answered Oct 21 '22 12:10

Andres