Avoid page scroll distance saved between views

Hi everyone!

I’m having a hard time trying to make my Vaadin app forget the scroll position after changing views in the main Panel. That Panel is the place where the app Navigator puts the Views.

Here is the situation:

  • I navigate to a long page with a button at the bottom
  • I press that button to navigate to another page
  • I navigate back to that long page
  • The scroll is in the bottom (the same place when I pressed the putton)

How could I avoid this? I would like to reset the scroll position everytime I navigate into a view.

Thank you all!


I think there is couple of option. First, if there is Focusable component (such as TextField or Button) you can set the focus to it when you enter the view.

@Override public void enter(ViewChangeEvent event) { tf.focus(); } Then, you can make simple Javascript Component (https://vaadin.com/book/-/page/gwt.javascript.html) for that purpose, which you can in the enter method.

Cool! Didn’t think about that!

I ended up arranging something like this, to scroll up the container (which happens to be a Panel, linked with the Navigator as the main View container for the app) everytime there is a change view event:

navigator.addViewChangeListener(new ViewChangeListener() {
   public boolean beforeViewChange(ViewChangeEvent event) {
      return true;

   public void afterViewChange(ViewChangeEvent event) {

Thanks a lot!