Google Web Toolkit (Beta)
Search this site:

# Class Window

public class Window
extends Object
This class provides access to the browser window's methods, properties, and events.

## Methods

addWindowCloseListener(WindowCloseListener) | Adds a listener to receive window closing events.
addWindowResizeListener(WindowResizeListener) | Adds a listener to receive window resize events.
alert(String) | Displays a message in a modal dialog box.
confirm(String) | Displays a message in a modal dialog box, along with the standard 'OK' and 'Cancel' buttons.
enableScrolling(boolean) | Use this method to explicitly disable the window's scrollbars.
getClientHeight() | Gets the height of the browser window's client area.
getClientWidth() | Gets the width of the browser window's client area.
getScrollLeft() | Gets the window's scroll left.
getScrollTop() | Get the window's scroll top.
getTitle() | Gets the browser window's current title.
open(String, String, String) | Opens a new browser window.
prompt(String, String) | Displays a request for information in a modal dialog box, along with the standard 'OK' and 'Cancel' buttons.
removeWindowCloseListener(WindowCloseListener) | Removes a window closing listener.
removeWindowResizeListener(WindowResizeListener) | Removes a window resize listener.
setMargin(String) | Sets the size of the margins used within the window's client area.
setTitle(String) | Sets the browser window's title.

## Method Detail

### addWindowCloseListener

public static void addWindowCloseListener(WindowCloseListener listener)
Adds a listener to receive window closing events.

#### Parameters

listener
  the listener to be informed when the window is closing

### addWindowResizeListener

public static void addWindowResizeListener(WindowResizeListener listener)
Adds a listener to receive window resize events.

#### Parameters

listener
  the listener to be informed when the window is resized

### alert

public static void alert(String msg)
Displays a message in a modal dialog box.

#### Parameters

msg
  the message to be displayed.

### confirm

public static boolean confirm(String msg)
Displays a message in a modal dialog box, along with the standard 'OK' and 'Cancel' buttons.

#### Parameters

msg
  the message to be displayed.

#### Return Value

`true` if 'OK' is clicked, `false` if 'Cancel' is clicked.

### enableScrolling

public static void enableScrolling(boolean enable)
Use this method to explicitly disable the window's scrollbars. Applications that choose to resize their user-interfaces to fit within the window's client area will normally want to disable window scrolling.

#### Parameters

enable
  `false` to disable window scrolling

### getClientHeight

public static int getClientHeight()
Gets the height of the browser window's client area.

#### Return Value

the window's client height

### getClientWidth

public static int getClientWidth()
Gets the width of the browser window's client area.

#### Return Value

the window's client width

### getScrollLeft

public static int getScrollLeft()
Gets the window's scroll left.

#### Return Value

window's scroll left

### getScrollTop

public static int getScrollTop()
Get the window's scroll top.

#### Return Value

the window's scroll top

### getTitle

public static String getTitle()
Gets the browser window's current title.

#### Return Value

the window's title.

### open

public static void open(String url, String name, String features)
Opens a new browser window. The "name" and "features" arguments are specified here.

#### Parameters

url
  the URL that the new window will display
name
  the name of the window (e.g. "_blank")
features
  the features to be enabled/disabled on this window

### prompt

public static String prompt(String msg, String initialValue)
Displays a request for information in a modal dialog box, along with the standard 'OK' and 'Cancel' buttons.

#### Parameters

msg
  the message to be displayed
initialValue
  the initial value in the dialog's text field

#### Return Value

the value entered by the user if 'OK' was pressed, or `null` if 'Cancel' was pressed

### removeWindowCloseListener

public static void removeWindowCloseListener(WindowCloseListener listener)
Removes a window closing listener.

#### Parameters

listener
  the listener to be removed

### removeWindowResizeListener

public static void removeWindowResizeListener(WindowResizeListener listener)
Removes a window resize listener.

#### Parameters

listener
  the listener to be removed

### setMargin

public static void setMargin(String size)
Sets the size of the margins used within the window's client area. It is sometimes necessary to do this because some browsers, such as Internet Explorer, add margins by default, which can confound attempts to resize panels to fit exactly within the window.

#### Parameters

size
  the window's new margin size, in CSS units.

### setTitle

public static void setTitle(String title)
Sets the browser window's title.

#### Parameters

title
  the new window title.