public class

LayoutPanel

extends ComplexPanel
implements AnimatedLayout ProvidesResize RequiresResize
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.LayoutPanel
Known Direct Subclasses

Class Overview

A panel that lays its children out in arbitrary layers using the Layout class.

This widget will only work in standards mode, which requires that the HTML page in which it is run have an explicit <!DOCTYPE> declaration.

Example

{@example com.google.gwt.examples.LayoutPanelExample}

Use in UiBinder Templates

LayoutPanel elements in UiBinder templates lay out their children with arbitrary constraints, using <g:layer> elements. Each layer may have any of the following constraint attributes specified as CSS length attributes: left, top, right, bottom, width , and height.

Precisely zero or two constraints are required for each axis (horizontal and vertical). Specifying no constraints implies that the child should fill that axis completely.

The valid sets of horizontal constraints are:

(none)
Fill the parent's horizontal axis
left, width
Fixed width, positioned from parent's left edge
right, width
Fixed width, positioned from parent's right edge
left, right
Width implied by fixed distance from parent's left and right edges

The valid sets of vertical constraints are:

(none)
Fill the parent's vertical axis
top, height
Fixed height, positioned from parent's top edge
bottom, height
Fixed height, positioned from parent's bottom edge
top, bottom
Height implied by fixed distance from parent's top and bottom edges

The values of constraint attributes can be any valid CSS length, such as 1px, 3em, or 0 (zero lengths require no units).

For example:

 <g:LayoutPanel>
   <!-- No constraints causes the layer to fill the parent -->
   <g:layer>
     <g:Label>Lorem ipsum...</g:Label>
   </g:layer>
   <!-- Position horizontally 25% from each edge;
        Vertically 4px from the top and 10em tall. -->
   <g:layer left='25%' right='25%' top='4px' height='10em'>
     <g:Label>Header</g:Label>
   </g:layer>
 </g:LayoutPanel>
 

Summary

[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Public Constructors
LayoutPanel()
Creates an empty layout panel.
Public Methods
void add(Widget widget)
Adds a widget to this panel.
void animate(int duration)
Layout children, animating over the specified period of time.
void animate(int duration, Layout.AnimationCallback callback)
Layout children, animating over the specified period of time.
void forceLayout()
Layout children immediately.
Element getWidgetContainerElement(Widget child)
Gets the container element wrapping the given child widget.
void insert(Widget widget, int beforeIndex)
Inserts a widget before the specified index.
void onResize()
This method must be called whenever the implementor's size has been modified.
boolean remove(Widget w)
Removes a child widget.
void setWidgetBottomHeight(Widget child, double bottom, Style.Unit bottomUnit, double height, Style.Unit heightUnit)
Sets the child widget's bottom and height values.
void setWidgetHorizontalPosition(Widget child, Layout.Alignment position)
Sets the child widget's horizontal position within its layer.
void setWidgetLeftRight(Widget child, double left, Style.Unit leftUnit, double right, Style.Unit rightUnit)
Sets the child widget's left and right values.
void setWidgetLeftWidth(Widget child, double left, Style.Unit leftUnit, double width, Style.Unit widthUnit)
Sets the child widget's left and width values.
void setWidgetRightWidth(Widget child, double right, Style.Unit rightUnit, double width, Style.Unit widthUnit)
Sets the child widget's right and width values.
void setWidgetTopBottom(Widget child, double top, Style.Unit topUnit, double bottom, Style.Unit bottomUnit)
Sets the child widget's top and bottom values.
void setWidgetTopHeight(Widget child, double top, Style.Unit topUnit, double height, Style.Unit heightUnit)
Sets the child widget's top and height values.
void setWidgetVerticalPosition(Widget child, Layout.Alignment position)
Sets the child widget's vertical position within its layer.
void setWidgetVisible(Widget child, boolean visible)
Shows or hides the given widget and its layer.
Protected Methods
void onLoad()
This method is called immediately after a widget becomes attached to the browser's document.
void onUnload()
This method is called immediately before a widget will be detached from the browser's document.
[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.AnimatedLayout
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.IsWidget
From interface com.google.gwt.user.client.ui.RequiresResize
From interface java.lang.Iterable

Public Constructors

public LayoutPanel ()

Creates an empty layout panel.

Public Methods

public void add (Widget widget)

Adds a widget to this panel.

By default, each child will fill the panel. To build more interesting layouts, set child widgets' layout constraints using setWidgetLeftRight(Widget, double, Style.Unit, double, Style.Unit) and related methods.

Parameters
widget the widget to be added

public void animate (int duration)

Layout children, animating over the specified period of time.

Parameters
duration the animation duration, in milliseconds

public void animate (int duration, Layout.AnimationCallback callback)

Layout children, animating over the specified period of time.

This method provides a callback that will be informed of animation updates. This can be used to create more complex animation effects.

Parameters
duration the animation duration, in milliseconds
callback the animation callback

public void forceLayout ()

Layout children immediately.

This is not normally necessary, unless you want to update child widgets' positions explicitly to create a starting point for a subsequent call to animate(int).

public Element getWidgetContainerElement (Widget child)

Gets the container element wrapping the given child widget.

Returns
  • the widget's container element

public void insert (Widget widget, int beforeIndex)

Inserts a widget before the specified index.

By default, each child will fill the panel. To build more interesting layouts, set child widgets' layout constraints using setWidgetLeftRight(Widget, double, Style.Unit, double, Style.Unit) and related methods.

Inserting a widget in this way has no effect on the DOM structure, but can be useful for other panels that wrap LayoutPanel to maintain insertion order.

Parameters
widget the widget to be inserted
beforeIndex the index before which it will be inserted
Throws
IndexOutOfBoundsException if beforeIndex is out of range

public void onResize ()

This method must be called whenever the implementor's size has been modified.

public boolean remove (Widget w)

Removes a child widget.

How to Override this Method

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

  1. Validate: Make sure this Panel is actually the parent of the child Widget; return false if it is not.
  2. Orphan: Call orphan(Widget) first while the child Widget is still attached.
  3. Physical Detach: Adjust the DOM to account for the removal of the child Widget. The Widget's Element must be physically removed from the DOM.
  4. Logical Detach: Update the Panel's state variables to reflect the removal of the child Widget. Example: the Widget is removed from the Panel's WidgetCollection.

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

public void setWidgetBottomHeight (Widget child, double bottom, Style.Unit bottomUnit, double height, Style.Unit heightUnit)

Sets the child widget's bottom and height values.

public void setWidgetHorizontalPosition (Widget child, Layout.Alignment position)

Sets the child widget's horizontal position within its layer.

public void setWidgetLeftRight (Widget child, double left, Style.Unit leftUnit, double right, Style.Unit rightUnit)

Sets the child widget's left and right values.

public void setWidgetLeftWidth (Widget child, double left, Style.Unit leftUnit, double width, Style.Unit widthUnit)

Sets the child widget's left and width values.

public void setWidgetRightWidth (Widget child, double right, Style.Unit rightUnit, double width, Style.Unit widthUnit)

Sets the child widget's right and width values.

public void setWidgetTopBottom (Widget child, double top, Style.Unit topUnit, double bottom, Style.Unit bottomUnit)

Sets the child widget's top and bottom values.

public void setWidgetTopHeight (Widget child, double top, Style.Unit topUnit, double height, Style.Unit heightUnit)

Sets the child widget's top and height values.

public void setWidgetVerticalPosition (Widget child, Layout.Alignment position)

Sets the child widget's vertical position within its layer.

public void setWidgetVisible (Widget child, boolean visible)

Shows or hides the given widget and its layer. This method explicitly calls setVisible(boolean) on the child widget and ensures that its associated layer is shown/hidden.

Protected Methods

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.