scroll to top when removing one component from panel

I am creating a panel, set it as scrollable, and then put many components into the panel, so the vertical scrollbar is displayed. each component has a delete button, which is used to remove the component from the panel. I wish the page position stay still when component is removed. but it will scroll to top automatically.

I also tried setScrollTop, but it still doesn’t work. Any help will be appreciated.


public void buttonClick(Button.ClickEvent event) {
                    int pos = component.getWindow().getScrollTop();
                    component.getParent().removeComponent(component);
                    component.getWindow().setScrollTop(pos);
 }

just get one way to solve this. Use two panels, panel A is set scrollable as false, and the panel B is set scrollable as true. put B into A, then it will work as i expected.
Not sure if it is the best way to do that. Any comments will be nice.

I don’t know how to keep the panel still but setScrollTop(pos) is explained here:
http://vaadin.com/api/com/vaadin/ui/Panel.html#setScrollTop(int)

I don’t think this is really the method you are looking for.

Here is another topic about someone who wants to scroll to the bottom when logdata is added. Perhaps it’s usefull for you? You should checkout the last post from Marko Grönroos too.
http://vaadin.com/forum/-/message_boards/message/97068#_19_message_303139

For all I know is that they used a hack to work around the problem. So it makes me think there isn’t a really good solution to this problem.

Thanks for your reply. I have checked source code of setScrollTop() and solved this issue.

  1. record the position using getScrollTop();
  2. invoke getWindow().requestRepaintAll();
  3. setScrollTop(pos),