tags:

views:

1449

answers:

1

For the GWT app I'm developing, I need to programmatically change the height of the browser window. Is there a way to do this in GWT? I've tried the following:

public static native void setWindowHeight(final int height) /*-{
    $wnd.resizeTo($wnd.outerWidth, height);
}-*/;

But this does not just change the height, it also messes with the width. Moreover, I would like to keep this resizing functionality within GWT Java code (this uses JSNI).

Edit: this actually does not interfere with the width of most browsers - it resizes to the previous width and new height. It does "mess" up the width in my Google hosted mode browser though for some reason.

I actually would prefer something that would resize the client area of the browser (i.e. excluding the browser's toolbars and scrollbars etc.) instead of the window itself.

For example, com.google.gwt.user.client.Window has the following methods: getClientWidth() and getClientHeight(). I would like something that would be equivalent to setClientWidth(int width) and setClientHeight(int height) (keep in mind that these setters don't actually exist).

+1  A: 

As far as I know, you'd have to use JSNI for such things. Window.scrollTo(...) is another method that would come in handy that's not available via the GWT Window.

What you could do though, is write your own extended Window that extends the GWT Window.

For instance:

public class ExtendedWindow extends Window {
    public static native void resizeTo(final int width, final int height) /*-{
        $wnd.resizeTo(width, height);
    }-*/;

    public static native void scrollTo(final int xpos, final int ypos) /*-{
        $wnd.scrollTo(xpos, ypos);
    }-*/;
    // ...etc...
}

You'd then use ExtendedWindow when you need these extended behaviors.

I don't believe setClientHeight() etc is going to be available, as this isn't available via Javascript. But I'm sure you can simulate it using resizeTo(...) by first first calculating the difference between outerHeight with clientHeight, and then maintaining the difference when you change the clientHeight.

I hope this is helpful.

Jack Leow