GWT - Widget Class



The class Widget is 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.

Class declaration

Following is the declaration for class:

public class Widget
   extends UIObject
      implements EventListener


Following are the fields for class:

  • public static final java.lang.String DEBUG_ID_PREFIX -- The element ID that you specify will be prefixed by the static string DEBUG_ID_PREFIX.

Class constructors

S.N.Constructor & Description


This creates a Widget for the child classes.

Class methods

S.N.Method & Description

protected <H extends EventHandler> HandlerRegistration addDomHandler(H handler, DomEvent.Type<H> type)

Adds a native event handler to the widget and sinks the corresponding native event.


protected <H extends EventHandler> HandlerRegistration addHandler(H handler, GwtEvent.Type<H> type)

Adds this handler to the widget.


protected void delegateEvent(Widget target, GwtEvent<?> event)

Fires an event on a child widget.


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.


void fireEvent(GwtEvent<?> event)

Fires the given event to all the appropriate handlers.


protected int getHandlerCount(GwtEvent.Type<?> type)

Gets the number of handlers listening to the event type.


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).
10protected boolean isOrWasAttached()
Has this widget ever been attached?
11protected void onAttach()
This method is called when a widget is attached to the browser's document.
12void onBrowserEvent(Event event)
Fired whenever a browser event is received.
13protected void onDetach()
This method is called when a widget is detached from the browser's document.
14protected void onLoad()
Gets a handle to the object's underlying DOM element.
15protected void onUnload()
This method is called immediately before a widget will be detached from the browser's document.
16void removeFromParent()
Removes this widget from its parent widget.
17void sinkEvents(int eventBitsToAdd)
Overridden to defer the call to super.sinkEvents until the first time this widget is attached to the dom, as a performance enhancement.

Methods inherited

This class inherits methods from the following classes: