public class

AbsolutePanel

extends ComplexPanel
implements InsertPanel.ForIsWidget
java.lang.Object
   ↳ com.google.gwt.user.client.ui.UIObject
     ↳ com.google.gwt.user.client.ui.Widget
       ↳ com.google.gwt.user.client.ui.Panel
         ↳ com.google.gwt.user.client.ui.ComplexPanel
           ↳ com.google.gwt.user.client.ui.AbsolutePanel
Known Direct Subclasses

Class Overview

An absolute panel positions all of its children absolutely, allowing them to overlap.

Note that this panel will not automatically resize itself to allow enough room for its absolutely-positioned children. It must be explicitly sized in order to make room for them.

Once a widget has been added to an absolute panel, the panel effectively "owns" the positioning of the widget. Any existing positioning attributes on the widget may be modified by the panel.

Use in UiBinder Templates

AbsolutePanel elements in UiBinder templates lay out their children with absolute position, using <g:at> elements. Each at element should have left and top attributes in pixels. They also can contain widget children directly, with no position specified.

For example:

 <g:AbsolutePanel>
   <g:at left='10' top='20'>
     <g:Label>Lorem ipsum...</g:Label>
   </g:at>
   <g:Label>...dolores est.</g:Label>
 </g:AbsolutePanel>
 

Summary

[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Public Constructors
AbsolutePanel()
Creates an empty absolute panel.
Protected Constructors
AbsolutePanel(Element elem)
Creates an AbsolutePanel with the given element.
Public Methods
void add(Widget w, int left, int top)
Adds a widget to the panel at the specified position.
void add(Widget w)
Adds a child widget.
int getWidgetLeft(Widget w)
Gets the position of the left outer border edge of the widget relative to the left outer border edge of the panel.
int getWidgetTop(Widget w)
Gets the position of the top outer border edge of the widget relative to the top outer border edge of the panel.
void insert(IsWidget w, int beforeIndex)
Convenience overload to allow IsWidget to be used directly.
void insert(Widget w, int left, int top, int beforeIndex)
Inserts a child widget at the specified position before the specified index.
void insert(Widget w, int beforeIndex)
Inserts a child widget before the specified index.
boolean remove(Widget w)
Overrides remove(Widget) to change the removed Widget's element back to static positioning.This is done so that any positioning changes to the widget that were done by the panel are undone when the widget is disowned from the panel.
void setWidgetPosition(Widget w, int left, int top)
Sets the position of the specified child widget.
Protected Methods
void setWidgetPositionImpl(Widget w, int left, int top)
[Expand]
Inherited Methods
From class com.google.gwt.user.client.ui.ComplexPanel
From class com.google.gwt.user.client.ui.Panel
From class com.google.gwt.user.client.ui.Widget
From class com.google.gwt.user.client.ui.UIObject
From class java.lang.Object
From interface com.google.gwt.event.logical.shared.HasAttachHandlers
From interface com.google.gwt.event.shared.HasHandlers
From interface com.google.gwt.user.client.EventListener
From interface com.google.gwt.user.client.ui.HasWidgets
From interface com.google.gwt.user.client.ui.HasWidgets.ForIsWidget
From interface com.google.gwt.user.client.ui.IndexedPanel
From interface com.google.gwt.user.client.ui.IndexedPanel.ForIsWidget
From interface com.google.gwt.user.client.ui.InsertPanel
From interface com.google.gwt.user.client.ui.InsertPanel.ForIsWidget
From interface com.google.gwt.user.client.ui.IsWidget
From interface java.lang.Iterable

Public Constructors

public AbsolutePanel ()

Creates an empty absolute panel.

Protected Constructors

protected AbsolutePanel (Element elem)

Creates an AbsolutePanel with the given element. This is protected so that it can be used by RootPanel or a subclass that wants to substitute another element. The element is presumed to be a <div>.

Parameters
elem the element to be used for this panel

Public Methods

public void add (Widget w, int left, int top)

Adds a widget to the panel at the specified position. Setting a position of (-1, -1) will cause the child widget to be positioned statically.

Parameters
w the widget to be added
left the widget's left position
top the widget's top position

public void add (Widget w)

Adds a child widget.

How to Override this Method

There are several important things that must take place in the correct order to properly add or insert a Widget to a Panel. Not all of these steps will be relevant to every Panel, but all of the steps must be considered.

  1. Validate: Perform any sanity checks to ensure the Panel can accept a new Widget. Examples: checking for a valid index on insertion; checking that the Panel is not full if there is a max capacity.
  2. Adjust for Reinsertion: Some Panels need to handle the case where the Widget is already a child of this Panel. Example: when performing a reinsert, the index might need to be adjusted to account for the Widget's removal. See adjustIndex(Widget, int).
  3. Detach Child: Remove the Widget from its existing parent, if any. Most Panels will simply call removeFromParent() on the Widget.
  4. Logical Attach: Any state variables of the Panel should be updated to reflect the addition of the new Widget. Example: the Widget is added to the Panel's WidgetCollection at the appropriate index.
  5. Physical Attach: The Widget's Element must be physically attached to the Panel's Element, either directly or indirectly.
  6. Adopt: Call adopt(Widget) to finalize the add as the very last step.

Parameters
w the widget to be added

public int getWidgetLeft (Widget w)

Gets the position of the left outer border edge of the widget relative to the left outer border edge of the panel.

Parameters
w the widget whose position is to be retrieved
Returns
  • the widget's left position

public int getWidgetTop (Widget w)

Gets the position of the top outer border edge of the widget relative to the top outer border edge of the panel.

Parameters
w the widget whose position is to be retrieved
Returns
  • the widget's top position

public void insert (IsWidget w, int beforeIndex)

Convenience overload to allow IsWidget to be used directly.

public void insert (Widget w, int left, int top, int beforeIndex)

Inserts a child widget at the specified position before the specified index. Setting a position of (-1, -1) will cause the child widget to be positioned statically. If the widget is already a child of this panel, it will be moved to the specified index.

Parameters
w the child widget to be inserted
left the widget's left position
top the widget's top position
beforeIndex the index before which it will be inserted
Throws
IndexOutOfBoundsException if beforeIndex is out of range

public void insert (Widget w, int beforeIndex)

Inserts a child widget before the specified index. If the widget is already a child of this panel, it will be moved to the specified index.

Parameters
w the child widget to be inserted
beforeIndex the index before which it will be inserted

public boolean remove (Widget w)

Overrides remove(Widget) to change the removed Widget's element back to static positioning.This is done so that any positioning changes to the widget that were done by the panel are undone when the widget is disowned from the panel.

Parameters
w the widget to be removed
Returns
  • true if the child was present

public void setWidgetPosition (Widget w, int left, int top)

Sets the position of the specified child widget. Setting a position of (-1, -1) will cause the child widget to be positioned statically.

Parameters
w the child widget to be positioned
left the widget's left position
top the widget's top position

Protected Methods

protected void setWidgetPositionImpl (Widget w, int left, int top)