Example usage for com.google.gwt.user.client.ui HasScrolling setHorizontalScrollPosition

List of usage examples for com.google.gwt.user.client.ui HasScrolling setHorizontalScrollPosition

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui HasScrolling setHorizontalScrollPosition.

Prototype

void setHorizontalScrollPosition(int position);

Source Link

Document

Sets the horizontal scroll position.

Usage

From source file:com.google.gwt.sample.showcase.client.content.cell.Cells.java

/**
 * Wrap the given cell so that if/*from   w  w  w  . j av  a  2  s. c o m*/
 * {@link Cell#resetFocus(com.google.gwt.cell.client.Cell.Context, Element, Object)} is
 * called on it, the wrapped cell will focus itself, but will also make sure that the
 * browser window doesn't automatically scroll the cell into view. This is handy for
 * cells that should respond to keyboard commands even when out of view.
 *
 * <p>Note that refocusing on top-level cells will happen automatically when a cell widget
 * is redrawn. One surprising cause of a redraws is that HasDataPresenter optimizes extensions
 * to a short list by just redoing the whole list. See
 * {@link com.google.gwt.user.cellview.client.HasDataPresenter#REDRAW_THRESHOLD} for what
 * can trigger redraws.
 */
public static <T> Cell<T> makeFocusableWithoutScrolling(Cell<T> cellToWrap, final HasScrolling scrollable) {
    return new CellAdapter<T, T>(cellToWrap, null, null) {
        @Override
        public boolean resetFocus(Context context, Element parent, T value) {
            int x = scrollable.getHorizontalScrollPosition();
            int y = scrollable.getVerticalScrollPosition();
            parent.focus();
            scrollable.setHorizontalScrollPosition(x);
            scrollable.setVerticalScrollPosition(y);
            return true;
        }
    };
}