Visibility of a selection in Table

Hi all,

I was wondering whether it is possible in Vaadin to programmatically scroll the Table so that the current selection is shown (or an arbitrary position in the Table; something in the spirit of JTable.scrollRectToVisible() in Swing).

Currently, I have a Table with hundreds of entries, and only a fraction of them is visible at the screen (one needs to scroll the table to see the rest of them). Some of these items are selected (using Table.setValue()) but the user may not be aware of that fact because the selected items are not always visible. Is there any method that would scroll the Table to the first selected item (or any item?)

Thanks for any help in advance!


http://vaadin.com/api/com/vaadin/ui/Table.html#setCurrentPageFirstItemId(java.lang.Object)

or

http://vaadin.com/api/com/vaadin/ui/Table.html#setCurrentPageFirstItemIndex(int)


package com.example.tabletest;

import com.vaadin.Application;
import com.vaadin.ui.Button;
import com.vaadin.ui.Table;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;

public class TabletestApplication extends Application {
    @Override
    public void init() {
        Window w = new Window("Tabletest Application");
        setMainWindow(w);
        final Table t = new Table();
        t.addContainerProperty("Foo", String.class, "");
        for (int i = 0; i < 1000; i++) {
            t.addItem(new Object[] { "row " + i }, "" + i);
        }
        w.addComponent(t);
        w.addComponent(new Button("Scroll to 500", new ClickListener() {

            public void buttonClick(ClickEvent event) {
                t.setCurrentPageFirstItemIndex(500);
            }
        }));
    }

}

Thanks! This works beautifully!