java.lang.Object
   ↳ com.google.gwt.user.client.ui.UIObject
     ↳ com.google.gwt.user.client.ui.Widget
       ↳ com.google.gwt.user.client.ui.Composite
         ↳ com.google.gwt.user.client.ui.ResizeComposite
           ↳ com.google.gwt.user.client.ui.StackLayoutPanel

Class Overview

A panel that stacks its children vertically, displaying only one at a time, with a header for each child which the user can click to display.

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

CSS Style Rules

.gwt-StackLayoutPanel
the panel itself
.gwt-StackLayoutPanel .gwt-StackLayoutPanelHeader
applied to each header widget
.gwt-StackLayoutPanel .gwt-StackLayoutPanelHeader-hovering
applied to each header widget on mouse hover
.gwt-StackLayoutPanel .gwt-StackLayoutPanelContent
applied to each child widget

Example

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

Use in UiBinder Templates

A StackLayoutPanel element in a UiBinder template may have a unit attribute with a Style.Unit value (it defaults to PX).

The children of a StackLayoutPanel element are laid out in <g:stack> elements. Each stack can have one widget child and one of two types of header elements. A <g:header> element can hold html, or a <g:customHeader> element can hold a widget. (Note that the tags of the header elements are not capitalized. This is meant to signal that the head is not a runtime object, and so cannot have a ui:field attribute.)

For example:

 <g:StackLayoutPanel unit='PX'>
  <g:stack>
    <g:header size='3'><b>HTML</b> header</g:header>
    <g:Label>able</g:Label>
  </g:stack>
  <g:stack>
    <g:customHeader size='3'>
      <g:Label>Custom header</g:Label>
    </g:customHeader>
    <g:Label>baker</g:Label>
  </g:stack>
 </g:StackLayoutPanel>
 

Summary

[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Public Constructors
StackLayoutPanel(Style.Unit unit)
Creates an empty stack panel.
Public Methods
void add(Widget widget, SafeHtml header, double headerSize)
Adds a child widget to this stack, along with a widget representing the stack header.
void add(Widget widget, Widget header, double headerSize)
Adds a child widget to this stack, along with a widget representing the stack header.
void add(Widget w)
Adds a child widget.
void add(Widget widget, String header, double headerSize)
Adds a child widget to this stack, along with a widget representing the stack header.
void add(Widget widget, String header, boolean asHtml, double headerSize)
Adds a child widget to this stack, along with a widget representing the stack header.
HandlerRegistration addBeforeSelectionHandler(BeforeSelectionHandler<Integer> handler)
HandlerRegistration addSelectionHandler(SelectionHandler<Integer> handler)
void clear()
Removes all child widgets.
Widget getHeaderWidget(int index)
Gets the widget in the stack header at the given index.
Widget getHeaderWidget(Widget child)
Gets the widget in the stack header associated with the given child widget.
int getVisibleIndex()
Gets the currently-selected index.
Widget getVisibleWidget()
Gets the currently-selected widget.
Widget getWidget(int index)
Gets the child widget at the specified index.
int getWidgetCount()
Gets the number of child widgets in this panel.
int getWidgetIndex(IsWidget child)
int getWidgetIndex(Widget child)
Gets the index of the specified child widget.
void insert(Widget child, String text, boolean asHtml, double headerSize, int beforeIndex)
Inserts a widget into the panel.
void insert(Widget child, SafeHtml html, double headerSize, int beforeIndex)
Inserts a widget into the panel.
void insert(Widget child, Widget header, double headerSize, int beforeIndex)
Inserts a widget into the panel.
void insert(Widget child, String text, double headerSize, int beforeIndex)
Inserts a widget into the panel.
Iterator<Widget> iterator()
Gets an iterator for the contained widgets.
void onResize()
This method must be called whenever the implementor's size has been modified.
boolean remove(Widget child)
Removes a child widget.
boolean remove(int index)
Removes the widget at the specified index.
void setHeaderHTML(int index, SafeHtml html)
Sets a stack header's HTML contents.
void setHeaderHTML(int index, String html)
Sets a stack header's HTML contents.
void setHeaderText(int index, String text)
Sets a stack header's text contents.
void showWidget(int index)
Shows the widget at the specified index and fires events.
void showWidget(Widget child, boolean fireEvents)
Shows the specified widget.
void showWidget(Widget child)
Shows the specified widget and fires events.
void showWidget(int index, boolean fireEvents)
Shows the widget at the specified index.
Protected Methods
void onLoad()
This method is called immediately after a widget becomes attached to the browser's document.
[Expand]
Inherited Methods
From class com.google.gwt.user.client.ui.ResizeComposite
From class com.google.gwt.user.client.ui.Composite
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.logical.shared.HasBeforeSelectionHandlers
From interface com.google.gwt.event.logical.shared.HasSelectionHandlers
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.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 StackLayoutPanel (Style.Unit unit)

Creates an empty stack panel.

Parameters
unit the unit to be used for layout

Public Methods

public void add (Widget widget, SafeHtml header, double headerSize)

Adds a child widget to this stack, along with a widget representing the stack header.

Parameters
widget the child widget to be added
header the html to be shown on its header
headerSize the size of the header widget

public void add (Widget widget, Widget header, double headerSize)

Adds a child widget to this stack, along with a widget representing the stack header.

Parameters
widget the child widget to be added
header the header widget
headerSize the size of the header widget

public void add (Widget w)

Adds a child widget.

Parameters
w the widget to be added

public void add (Widget widget, String header, double headerSize)

Adds a child widget to this stack, along with a widget representing the stack header.

Parameters
widget the child widget to be added
header the text to be shown on its header
headerSize the size of the header widget

public void add (Widget widget, String header, boolean asHtml, double headerSize)

Adds a child widget to this stack, along with a widget representing the stack header.

Parameters
widget the child widget to be added
header the text to be shown on its header
asHtml true to treat the specified text as HTML
headerSize the size of the header widget

public HandlerRegistration addBeforeSelectionHandler (BeforeSelectionHandler<Integer> handler)

public HandlerRegistration addSelectionHandler (SelectionHandler<Integer> handler)

public void clear ()

Removes all child widgets.

public Widget getHeaderWidget (int index)

Gets the widget in the stack header at the given index.

Parameters
index the index of the stack header to be retrieved
Returns
  • the header widget

public Widget getHeaderWidget (Widget child)

Gets the widget in the stack header associated with the given child widget.

Parameters
child the child whose stack header is to be retrieved
Returns
  • the header widget

public int getVisibleIndex ()

Gets the currently-selected index.

Returns
  • the selected index, or -1 if none is selected

public Widget getVisibleWidget ()

Gets the currently-selected widget.

Returns
  • the selected widget, or null if none exist

public Widget getWidget (int index)

Gets the child widget at the specified index.

Parameters
index the child widget's index
Returns
  • the child widget

public int getWidgetCount ()

Gets the number of child widgets in this panel.

Returns
  • the number of children

public int getWidgetIndex (IsWidget child)

public int getWidgetIndex (Widget child)

Gets the index of the specified child widget.

Parameters
child the widget to be found
Returns
  • the widget's index, or -1 if it is not a child of this panel

public void insert (Widget child, String text, boolean asHtml, double headerSize, int beforeIndex)

Inserts a widget into the panel. If the Widget is already attached, it will be moved to the requested index.

Parameters
child the widget to be added
text the text to be shown on its header
asHtml true to treat the specified text as HTML
headerSize the size of the header widget
beforeIndex the index before which it will be inserted

public void insert (Widget child, SafeHtml html, double headerSize, int beforeIndex)

Inserts a widget into the panel. If the Widget is already attached, it will be moved to the requested index.

Parameters
child the widget to be added
html the safe html to be shown on its header
headerSize the size of the header widget
beforeIndex the index before which it will be inserted

public void insert (Widget child, Widget header, double headerSize, int beforeIndex)

Inserts a widget into the panel. If the Widget is already attached, it will be moved to the requested index.

Parameters
child the widget to be added
header the widget to be placed in the associated header
headerSize the size of the header widget
beforeIndex the index before which it will be inserted

public void insert (Widget child, String text, double headerSize, int beforeIndex)

Inserts a widget into the panel. If the Widget is already attached, it will be moved to the requested index.

Parameters
child the widget to be added
text the text to be shown on its header
headerSize the size of the header widget
beforeIndex the index before which it will be inserted

public Iterator<Widget> iterator ()

Gets an iterator for the contained widgets. This iterator is required to implement remove().

public void onResize ()

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

public boolean remove (Widget child)

Removes a child widget.

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

public boolean remove (int index)

Removes the widget at the specified index.

Parameters
index the index of the widget to be removed
Returns
  • false if the widget is not present

public void setHeaderHTML (int index, SafeHtml html)

Sets a stack header's HTML contents.

Parameters
index the index of the header whose HTML is to be set
html the header's new HTML contents

public void setHeaderHTML (int index, String html)

Sets a stack header's HTML contents. Use care when setting an object's HTML; it is an easy way to expose script-based security problems. Consider using setHeaderHTML(int, SafeHtml) or setHeaderText(int, String) whenever possible.

Parameters
index the index of the header whose HTML is to be set
html the header's new HTML contents

public void setHeaderText (int index, String text)

Sets a stack header's text contents.

Parameters
index the index of the header whose text is to be set
text the object's new text

public void showWidget (int index)

Shows the widget at the specified index and fires events.

Parameters
index the index of the child widget to be shown.

public void showWidget (Widget child, boolean fireEvents)

Shows the specified widget.

Parameters
child the child widget to be shown.
fireEvents true to fire events, false not to

public void showWidget (Widget child)

Shows the specified widget and fires events.

Parameters
child the child widget to be shown.

public void showWidget (int index, boolean fireEvents)

Shows the widget at the specified index.

Parameters
index the index of the child widget to be shown.
fireEvents true to fire events, false not to

Protected Methods

protected void onLoad ()

This method is called immediately after a widget becomes attached to the browser's document.