public class

StackPanel

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.StackPanel
Known Direct Subclasses

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 quirks mode. If your application is in Standards Mode, use StackLayoutPanel instead.

CSS Style Rules

  • .gwt-StackPanel { the panel itself }
  • .gwt-StackPanel .gwt-StackPanelItem { unselected items }
  • .gwt-StackPanel .gwt-StackPanelItem-selected { selected items }
  • .gwt-StackPanel .gwt-StackPanelContent { the wrapper around the contents of the item }

Example

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

See Also

Summary

[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Public Constructors
StackPanel()
Creates an empty stack panel.
Public Methods
void add(Widget w, SafeHtml stackHtml)
Adds a new child with the given widget and header, optionally interpreting the header as HTML.
void add(Widget w, String stackText)
Adds a new child with the given widget and header.
void add(Widget w, String stackText, boolean asHTML)
Adds a new child with the given widget and header, optionally interpreting the header as HTML.
void add(Widget w)
Adds a child widget.
int getSelectedIndex()
Gets the currently selected child index.
void insert(IsWidget w, int beforeIndex)
void insert(Widget w, int beforeIndex)
Inserts a child widget before the specified index.
void onBrowserEvent(Event event)
Fired whenever a browser event is received.
boolean remove(Widget child)
Removes a child widget.
boolean remove(int index)
Removes the widget at the specified index.
void setStackText(int index, String text, boolean asHTML)
Sets the text associated with a child by its index.
void setStackText(int index, String text)
Sets the text associated with a child by its index.
void setStackText(int index, SafeHtml html)
Sets the html associated with a child by its index.
void showStack(int index)
Shows the widget at the specified child index.
Protected Methods
void onEnsureDebugId(String baseID)
Affected Elements:
  • -text# = The element around the header at the specified index.
[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 StackPanel ()

Creates an empty stack panel.

Public Methods

public void add (Widget w, SafeHtml stackHtml)

Adds a new child with the given widget and header, optionally interpreting the header as HTML.

Parameters
w the widget to be added
stackHtml the header html associated with this widget

public void add (Widget w, String stackText)

Adds a new child with the given widget and header.

Parameters
w the widget to be added
stackText the header text associated with this widget

public void add (Widget w, String stackText, boolean asHTML)

Adds a new child with the given widget and header, optionally interpreting the header as HTML.

Parameters
w the widget to be added
stackText the header text associated with this widget
asHTML true to treat the specified text as HTML

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 getSelectedIndex ()

Gets the currently selected child index.

Returns
  • selected child

public void insert (IsWidget w, int beforeIndex)

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 void onBrowserEvent (Event event)

Fired whenever a browser event is received.

Parameters
event the event received

public boolean remove (Widget child)

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
child the widget to be removed
Returns
  • true if the child 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 setStackText (int index, String text, boolean asHTML)

Sets the text associated with a child by its index.

Parameters
index the index of the child whose text is to be set
text the text to be associated with it
asHTML true to treat the specified text as HTML

public void setStackText (int index, String text)

Sets the text associated with a child by its index.

Parameters
index the index of the child whose text is to be set
text the text to be associated with it

public void setStackText (int index, SafeHtml html)

Sets the html associated with a child by its index.

Parameters
index the index of the child whose text is to be set
html the html to be associated with it

public void showStack (int index)

Shows the widget at the specified child index.

Parameters
index the index of the child to be shown

Protected Methods

protected void onEnsureDebugId (String baseID)

Affected Elements:

  • -text# = The element around the header at the specified index.
  • -text-wrapper# = The element around the header at the specified index.
  • -content# = The element around the body at the specified index.

Parameters
baseID the base ID used by the main element