Google Web Toolkit (Beta)
Search this site:

# Class Panel

public class Panel
extends Widget
implements HasWidgets
// Superclass of `SimplePanel`, `HTMLTable`, `ComplexPanel`
Abstract base class for all panels, which are widgets that can contain other widgets.

## Methods

add(Widget) | Adds a child widget.
adopt(Widget, Element) | This method must be called as part of the add method of any panel.
clear() | Removes all child widgets.
disown(Widget) | This method must be called whenever a Widget is removed.
onAttach() | This method is called when a widget is attached to the browser's document.
onDetach() | This method is called when a widget is detached from the browser's document.

## Method Detail

### add

public void add(Widget w)
Adds a child widget.

#### Parameters

w
  the widget to be added

### adopt

protected void adopt(Widget w, Element container)
This method must be called as part of the add method of any panel. It ensures that the Widget's parent is set properly, and that it is removed from any existing parent widget. It also attaches the child widget's DOM element to its new container, ensuring that this process occurs in the right order.

#### Parameters

w
  the widget to be adopted
container
  the element within which it will be contained

### clear

public void clear()
Removes all child widgets.

### disown

protected void disown(Widget w)
This method must be called whenever a Widget is removed. It ensures that the Widget's parent is cleared.

#### Parameters

w
  the widget to be disowned

### 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 from the document, override the onLoad method.

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

### 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 memeroy leaks due to circular references between DOM Elements and JavaScript objects.