## com.google.gwt.user.client.ui
Class Widget

    java.lang.Object
      com.google.gwt.user.client.ui.UIObject
          com.google.gwt.user.client.ui.Widget

All Implemented Interfaces:
  EventListener

Direct Known Subclasses:
  Composite, FileUpload, FocusWidget, Frame, Hidden, Hyperlink, Image, Label, MenuBar, Panel, Tree

    public class Widget

extends UIObject
implements EventListener

The base class for the majority of user-interface objects. Widget adds support for receiving events from the browser and being added directly to `panels`.

Constructor Summary
`Widget()`

Method Summary
`protected void` `doAttachChildren()` If a widget implements HasWidgets, it must override this method and call onAttach() for each of its child widgets.
`protected void` `doDetachChildren()` If a widget implements HasWidgets, it must override this method and call onDetach() for each of its child widgets.
`Widget` `getParent()` Gets this widget's parent panel.
`boolean` `isAttached()` Determines whether this widget is currently attached to the browser's document (i.e., there is an unbroken chain of widgets between this widget and the underlying browser document).
`protected void` `onAttach()` This method is called when a widget is attached to the browser's document.
`void` `onBrowserEvent(Event event)` Fired whenever a browser event is received.
`protected void` `onDetach()` This method is called when a widget is detached from the browser's document.
`protected void` `onLoad()` This method is called immediately after a widget becomes attached to the browser's document.
`protected void` `onUnload()` This method is called immediately before a widget will be detached from the browser's document.
`void` `removeFromParent()` Removes this widget from its parent widget.
`protected void` `setElement(Element elem)` Sets this object's browser element.

Methods inherited from class com.google.gwt.user.client.ui.UIObject

`addStyleDependentName, addStyleName, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkEvents, toString, unsinkEvents`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### Widget

    public Widget()

Method Detail

### getParent

    public Widget getParent()

  Gets this widget's parent panel.

  Returns:
    the widget's parent panel

### isAttached

    public boolean isAttached()

  Determines whether this widget is currently attached to the browser's document (i.e., there is an unbroken chain of widgets between this widget and the underlying browser document).

  Returns:
    `true` if the widget is attached

### onBrowserEvent

    public void onBrowserEvent(Event event)

  Description copied from interface: `EventListener`
  Fired whenever a browser event is received.

  Specified by:
    `onBrowserEvent` in interface `EventListener`
  Parameters:
    `event` - the event received

### removeFromParent

    public void removeFromParent()

  Removes this widget from its parent widget. If it has no parent, this method does nothing.

  Throws:
    `java.lang.IllegalStateException` - if this widget's parent does not support removal (e.g. `Composite`)

### doAttachChildren

    protected void doAttachChildren()

  If a widget implements HasWidgets, it must override this method and call onAttach() for each of its child widgets.

  See Also:
    `onAttach()`

### doDetachChildren

    protected void doDetachChildren()

  If a widget implements HasWidgets, it must override this method and call onDetach() for each of its child widgets.

  See Also:
    `onDetach()`

### onAttach

    protected void onAttach()

  This method is called when a widget is attached to the browser's document. To receive notification after a Widget has been added to the document, override the `onLoad()` method.

  Subclasses that override this method must call `super.onAttach()` to ensure that the Widget has been attached to its underlying Element.

  Throws:
    `java.lang.IllegalStateException` - if this widget is already attached

### onDetach

    protected void onDetach()

  This method is called when a widget is detached from the browser's document. To receive notification before a Widget is removed from the document, override the `onUnload()` method.

  Subclasses that override this method must call `super.onDetach()` to ensure that the Widget has been detached from the underlying Element. Failure to do so will result in application memory leaks due to circular references between DOM Elements and JavaScript objects.

  Throws:
    `java.lang.IllegalStateException` - if this widget is already detached

### onLoad

    protected void onLoad()

  This method is called immediately after a widget becomes attached to the browser's document.

### onUnload

    protected void onUnload()

  This method is called immediately before a widget will be detached from the browser's document.

### setElement

    protected void setElement(Element elem)

  Sets this object's browser element. Widget subclasses must call this method before attempting to call any other methods. If a browser element has already been attached, then it is replaced with the new element. The old event listeners are removed from the old browser element, and the event listeners are set up on the new browser element.

  Overrides:
    `setElement` in class `UIObject`
  Parameters:
    `elem` - the object's new element