Class LayoutPanel
- 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
-
- All Implemented Interfaces:
HasAttachHandlers,HasHandlers,EventListener,AnimatedLayout,HasVisibility,HasWidgets,HasWidgets.ForIsWidget,IndexedPanel,IndexedPanel.ForIsWidget,IsWidget,ProvidesResize,RequiresResize,java.lang.Iterable<Widget>
- Direct Known Subclasses:
RootLayoutPanel
public class LayoutPanel extends ComplexPanel implements AnimatedLayout, RequiresResize, ProvidesResize
A panel that lays its children out in arbitrarylayersusing theLayoutclass.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
public class LayoutPanelExample implements EntryPoint { public void onModuleLoad() { // Attach two child widgets to a LayoutPanel, laying them out horizontally, // splitting at 50%. Widget childOne = new HTML("left"), childTwo = new HTML("right"); LayoutPanel p = new LayoutPanel(); p.add(childOne); p.add(childTwo); p.setWidgetLeftWidth(childOne, 0, PCT, 50, PCT); p.setWidgetRightWidth(childTwo, 0, PCT, 50, PCT); // Attach the LayoutPanel to the RootLayoutPanel. The latter will listen for // resize events on the window to ensure that its children are informed of // possible size changes. RootLayoutPanel rp = RootLayoutPanel.get(); rp.add(p); } }Use in UiBinder Templates
LayoutPanel elements in
UiBindertemplates 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, andheight.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, or0(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>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
-
Nested classes/interfaces inherited from interface com.google.gwt.user.client.ui.HasWidgets
HasWidgets.ForIsWidget
-
Nested classes/interfaces inherited from interface com.google.gwt.user.client.ui.IndexedPanel
IndexedPanel.ForIsWidget
-
-
Field Summary
-
Fields inherited from class com.google.gwt.user.client.ui.Widget
eventsToSink
-
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR
-
-
Constructor Summary
Constructors Constructor Description LayoutPanel()Creates an empty layout panel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Widget widget)Adds a widget to this panel.voidanimate(int duration)Layout children, animating over the specified period of time.voidanimate(int duration, Layout.AnimationCallback callback)Layout children, animating over the specified period of time.voidforceLayout()Layout children immediately.(package private) LayoutgetLayout()Gets theLayoutinstance associated with this widget.ElementgetWidgetContainerElement(Widget child)Gets the container element wrapping the given child widget.voidinsert(Widget widget, int beforeIndex)Inserts a widget before the specified index.protected voidonAttach()This method is called when a widget is attached to the browser's document.protected voidonDetach()This method is called when a widget is detached from the browser's document.voidonResize()This method must be called whenever the implementor's size has been modified.booleanremove(Widget w)Removes a child widget.voidsetWidgetBottomHeight(IsWidget child, double bottom, Style.Unit bottomUnit, double height, Style.Unit heightUnit)Overloaded version for IsWidget.voidsetWidgetBottomHeight(Widget child, double bottom, Style.Unit bottomUnit, double height, Style.Unit heightUnit)Sets the child widget's bottom and height values.voidsetWidgetHorizontalPosition(Widget child, Layout.Alignment position)Sets the child widget's horizontal position within its layer.voidsetWidgetLeftRight(IsWidget child, double left, Style.Unit leftUnit, double right, Style.Unit rightUnit)Overloaded version for IsWidget.voidsetWidgetLeftRight(Widget child, double left, Style.Unit leftUnit, double right, Style.Unit rightUnit)Sets the child widget's left and right values.voidsetWidgetLeftWidth(IsWidget child, double left, Style.Unit leftUnit, double width, Style.Unit widthUnit)Overloaded version for IsWidget.voidsetWidgetLeftWidth(Widget child, double left, Style.Unit leftUnit, double width, Style.Unit widthUnit)Sets the child widget's left and width values.voidsetWidgetRightWidth(IsWidget child, double right, Style.Unit rightUnit, double width, Style.Unit widthUnit)Overloaded version for IsWidget.voidsetWidgetRightWidth(Widget child, double right, Style.Unit rightUnit, double width, Style.Unit widthUnit)Sets the child widget's right and width values.voidsetWidgetTopBottom(IsWidget child, double top, Style.Unit topUnit, double bottom, Style.Unit bottomUnit)Overloaded version for IsWidget.voidsetWidgetTopBottom(Widget child, double top, Style.Unit topUnit, double bottom, Style.Unit bottomUnit)Sets the child widget's top and bottom values.voidsetWidgetTopHeight(IsWidget child, double top, Style.Unit topUnit, double height, Style.Unit heightUnit)Overloaded version for IsWidget.voidsetWidgetTopHeight(Widget child, double top, Style.Unit topUnit, double height, Style.Unit heightUnit)Sets the child widget's top and height values.voidsetWidgetVerticalPosition(Widget child, Layout.Alignment position)Sets the child widget's vertical position within its layer.voidsetWidgetVisible(Widget child, boolean visible)Shows or hides the given widget and its layer.-
Methods inherited from class com.google.gwt.user.client.ui.ComplexPanel
add, add, adjustIndex, checkIndexBoundsForAccess, checkIndexBoundsForInsertion, doLogicalClear, getChildren, getWidget, getWidgetCount, getWidgetIndex, getWidgetIndex, insert, insert, iterator, remove
-
Methods inherited from class com.google.gwt.user.client.ui.Panel
add, adopt, clear, doAttachChildren, doDetachChildren, orphan, remove
-
Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, ensureHandlers, fireEvent, getHandlerCount, getHandlerManager, getLayoutData, getParent, isAttached, isOrWasAttached, onBrowserEvent, onLoad, onUnload, removeFromParent, replaceElement, setLayoutData, setParent, sinkEvents, unsinkEvents
-
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
-
-
-
-
Method Detail
-
add
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.- Specified by:
addin interfaceHasWidgets- Overrides:
addin classPanel- Parameters:
widget- the widget to be added- See Also:
HasWidgets.add(Widget)
-
animate
public void animate(int duration)
Description copied from interface:AnimatedLayoutLayout children, animating over the specified period of time.- Specified by:
animatein interfaceAnimatedLayout- Parameters:
duration- the animation duration, in milliseconds
-
animate
public void animate(int duration, Layout.AnimationCallback callback)Description copied from interface:AnimatedLayoutLayout 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.
- Specified by:
animatein interfaceAnimatedLayout- Parameters:
duration- the animation duration, in millisecondscallback- the animation callback
-
forceLayout
public void forceLayout()
Description copied from interface:AnimatedLayoutLayout 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
AnimatedLayout.animate(int).- Specified by:
forceLayoutin interfaceAnimatedLayout- See Also:
AnimatedLayout.animate(int),AnimatedLayout.animate(int, Layout.AnimationCallback)
-
getWidgetContainerElement
public Element getWidgetContainerElement(Widget child)
Gets the container element wrapping the given child widget.- Parameters:
child-- Returns:
- the widget's container element
-
insert
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 insertedbeforeIndex- the index before which it will be inserted- Throws:
java.lang.IndexOutOfBoundsException- ifbeforeIndexis out of range
-
onResize
public void onResize()
Description copied from interface:RequiresResizeThis method must be called whenever the implementor's size has been modified.- Specified by:
onResizein interfaceRequiresResize
-
remove
public boolean remove(Widget w)
Description copied from class:PanelRemoves 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.
- Validate: Make sure this Panel is actually the parent of the
child Widget; return
falseif it is not. - Orphan: Call
Panel.orphan(Widget)first while the child Widget is still attached. - 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.
- 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.
- Specified by:
removein interfaceHasWidgets- Overrides:
removein classComplexPanel- Parameters:
w- the widget to be removed- Returns:
trueif the child was present
- Validate: Make sure this Panel is actually the parent of the
child Widget; return
-
setWidgetBottomHeight
public void setWidgetBottomHeight(Widget child, double bottom, Style.Unit bottomUnit, double height, Style.Unit heightUnit)
Sets the child widget's bottom and height values.- Parameters:
child-bottom-bottomUnit-height-heightUnit-
-
setWidgetBottomHeight
public void setWidgetBottomHeight(IsWidget child, double bottom, Style.Unit bottomUnit, double height, Style.Unit heightUnit)
Overloaded version for IsWidget.
-
setWidgetHorizontalPosition
public void setWidgetHorizontalPosition(Widget child, Layout.Alignment position)
Sets the child widget's horizontal position within its layer.- Parameters:
child-position-
-
setWidgetLeftRight
public void setWidgetLeftRight(Widget child, double left, Style.Unit leftUnit, double right, Style.Unit rightUnit)
Sets the child widget's left and right values.- Parameters:
child-left-leftUnit-right-rightUnit-
-
setWidgetLeftRight
public void setWidgetLeftRight(IsWidget child, double left, Style.Unit leftUnit, double right, Style.Unit rightUnit)
Overloaded version for IsWidget.
-
setWidgetLeftWidth
public void setWidgetLeftWidth(Widget child, double left, Style.Unit leftUnit, double width, Style.Unit widthUnit)
Sets the child widget's left and width values.- Parameters:
child-left-leftUnit-width-widthUnit-
-
setWidgetLeftWidth
public void setWidgetLeftWidth(IsWidget child, double left, Style.Unit leftUnit, double width, Style.Unit widthUnit)
Overloaded version for IsWidget.
-
setWidgetRightWidth
public void setWidgetRightWidth(Widget child, double right, Style.Unit rightUnit, double width, Style.Unit widthUnit)
Sets the child widget's right and width values.- Parameters:
child-right-rightUnit-width-widthUnit-
-
setWidgetRightWidth
public void setWidgetRightWidth(IsWidget child, double right, Style.Unit rightUnit, double width, Style.Unit widthUnit)
Overloaded version for IsWidget.
-
setWidgetTopBottom
public void setWidgetTopBottom(Widget child, double top, Style.Unit topUnit, double bottom, Style.Unit bottomUnit)
Sets the child widget's top and bottom values.- Parameters:
child-top-topUnit-bottom-bottomUnit-
-
setWidgetTopBottom
public void setWidgetTopBottom(IsWidget child, double top, Style.Unit topUnit, double bottom, Style.Unit bottomUnit)
Overloaded version for IsWidget.
-
setWidgetTopHeight
public void setWidgetTopHeight(Widget child, double top, Style.Unit topUnit, double height, Style.Unit heightUnit)
Sets the child widget's top and height values.- Parameters:
child-top-topUnit-height-heightUnit-
-
setWidgetTopHeight
public void setWidgetTopHeight(IsWidget child, double top, Style.Unit topUnit, double height, Style.Unit heightUnit)
Overloaded version for IsWidget.
-
setWidgetVerticalPosition
public void setWidgetVerticalPosition(Widget child, Layout.Alignment position)
Sets the child widget's vertical position within its layer.- Parameters:
child-position-
-
setWidgetVisible
public void setWidgetVisible(Widget child, boolean visible)
Shows or hides the given widget and its layer. This method explicitly callsUIObject.setVisible(boolean)on the child widget and ensures that its associated layer is shown/hidden.- Parameters:
child-visible-
-
onAttach
protected void onAttach()
Description copied from class:WidgetThis 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
Widget.onLoad()method or useWidget.addAttachHandler(com.google.gwt.event.logical.shared.AttachEvent.Handler).It is strongly recommended that you override
Widget.onLoad()orWidget.doAttachChildren()instead of this method to avoid inconsistencies between logical and physical attachment states.Subclasses that override this method must call
super.onAttach()to ensure that the Widget has been attached to its underlying Element.- Overrides:
onAttachin classWidget- See Also:
Widget.onLoad(),Widget.doAttachChildren()
-
onDetach
protected void onDetach()
Description copied from class:WidgetThis 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
Widget.onUnload()method or useWidget.addAttachHandler(com.google.gwt.event.logical.shared.AttachEvent.Handler).It is strongly recommended that you override
Widget.onUnload()orWidget.doDetachChildren()instead of this method to avoid inconsistencies between logical and physical attachment states.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.- Overrides:
onDetachin classWidget- See Also:
Widget.onUnload(),Widget.doDetachChildren()
-
getLayout
Layout getLayout()
Gets theLayoutinstance associated with this widget. This is made package-protected for use byRootLayoutPanel.- Returns:
- this widget's layout instance
-
-