Class TabLayoutPanel
- All Implemented Interfaces:
HasAttachHandlers,HasBeforeSelectionHandlers<Integer>,HasSelectionHandlers<Integer>,HasHandlers,EventListener,AnimatedLayout,HasVisibility,HasWidgets,IndexedPanel,IndexedPanel.ForIsWidget,IsRenderable,IsWidget,ProvidesResize,RequiresResize,Iterable<Widget>
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-TabLayoutPanel
- the panel itself
- .gwt-TabLayoutPanel .gwt-TabLayoutPanelTabs
- the tab bar element
- .gwt-TabLayoutPanel .gwt-TabLayoutPanelTab
- an individual tab
- .gwt-TabLayoutPanel .gwt-TabLayoutPanelTabInner
- an element nested in each tab (useful for styling)
- .gwt-TabLayoutPanel .gwt-TabLayoutPanelContent
- applied to all child content widgets
Example
public class TabLayoutPanelExample implements EntryPoint {
public void onModuleLoad() {
// Create a three-item tab panel, with the tab area 1.5em tall.
TabLayoutPanel p = new TabLayoutPanel(1.5, Unit.EM);
p.add(new HTML("this"), "[this]");
p.add(new HTML("that"), "[that]");
p.add(new HTML("the other"), "[the other]");
// 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
A TabLayoutPanel element in a UiBinder template must have a barHeight attribute with a double
value, and may have a barUnit attribute with a
Style.Unit value.
barUnit defaults to PX.
The children of a TabLayoutPanel element are laid out in <g:tab>
elements. Each tab 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:TabLayoutPanel barUnit='EM' barHeight='3'>
<g:tab>
<g:header size='7'><b>HTML</b> header</g:header>
<g:Label>able</g:Label>
</g:tab>
<g:tab>
<g:customHeader size='7'>
<g:Label>Custom header</g:Label>
</g:customHeader>
<g:Label>baker</g:Label>
</g:tab>
</g:TabLayoutPanel>
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabledNested classes/interfaces inherited from interface com.google.gwt.user.client.ui.HasWidgets
HasWidgets.ForIsWidgetNested 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
eventsToSinkFields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR -
Constructor Summary
ConstructorsConstructorDescriptionTabLayoutPanel(double barHeight, Style.Unit barUnit) Creates an empty tab panel. -
Method Summary
Modifier and TypeMethodDescriptionvoidConvenience overload to allowIsWidgetto be used directly.voidConvenience overload to allowIsWidgetto be used directly.voidConvenience overload to allowIsWidgetto be used directly.voidConvenience overload to allowIsWidgetto be used directly.voidAdds a child widget.voidAdds a widget to the panel.voidAdds a widget to the panel.voidAdds a widget to the panel.voidAdds a widget to the panel.Adds aBeforeSelectionEventhandler.addSelectionHandler(SelectionHandler<Integer> handler) Adds aSelectionEventhandler.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.voidclear()Removes all child widgets.voidLayout children immediately.intGet the duration of the animated transition between tabs.intGets the index of the currently-selected tab.getTabWidget(int index) Gets the widget in the tab at the given index.getTabWidget(IsWidget child) Convenience overload to allowIsWidgetto be used directly.getTabWidget(Widget child) Gets the widget in the tab associated with the given child widget.getWidget(int index) Returns the widget at the given index.intReturns the number of tabs and widgets.intgetWidgetIndex(IsWidget child) Convenience overload to allowIsWidgetto be used directly.intgetWidgetIndex(Widget child) Returns the index of the given child, or -1 if it is not a child.voidConvenience overload to allowIsWidgetto be used directly.voidConvenience overload to allowIsWidgetto be used directly.voidConvenience overload to allowIsWidgetto be used directly.voidConvenience overload to allowIsWidgetto be used directly.voidInserts a widget into the panel.voidInserts a widget into the panel.voidInserts a widget into the panel.voidInserts a widget into the panel.voidInserts a widget into the panel.booleanCheck whether or not transitions slide in vertically or horizontally.iterator()Gets an iterator for the contained widgets.booleanremove(int index) Removes the widget at the specified index.booleanRemoves a child widget.voidselectTab(int index) Programmatically selects the specified tab and fires events.voidselectTab(int index, boolean fireEvents) Programmatically selects the specified tab.voidConvenience overload to allowIsWidgetto be used directly.voidConvenience overload to allowIsWidgetto be used directly.voidProgrammatically selects the specified tab and fires events.voidProgrammatically selects the specified tab.voidsetAnimationDuration(int duration) Set the duration of the animated transition between tabs.voidsetAnimationVertical(boolean isVertical) Set whether or not transitions slide in vertically or horizontally.voidsetTabHTML(int index, SafeHtml html) Sets a tab's HTML contents.voidsetTabHTML(int index, String html) Sets a tab's HTML contents.voidsetTabText(int index, String text) Sets a tab's text contents.Methods inherited from class com.google.gwt.user.client.ui.ResizeComposite
initWidget, onResizeMethods inherited from class com.google.gwt.user.client.ui.Composite
claimElement, getWidget, initializeClaimedElement, isAttached, onAttach, onBrowserEvent, onDetach, render, render, resolvePotentialElement, setWidgetMethods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, ensureHandlers, fireEvent, getHandlerCount, getHandlerManager, getLayoutData, getParent, isOrWasAttached, onLoad, onUnload, removeFromParent, replaceElement, setLayoutData, setParent, sinkEvents, unsinkEventsMethods 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, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEventMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
TabLayoutPanel
Creates an empty tab panel.- Parameters:
barHeight- the size of the tab barbarUnit- the unit in which the tab bar size is specified
-
-
Method Details
-
add
Convenience overload to allowIsWidgetto be used directly. -
add
Convenience overload to allowIsWidgetto be used directly. -
add
Convenience overload to allowIsWidgetto be used directly. -
add
Convenience overload to allowIsWidgetto be used directly. -
add
Description copied from interface:HasWidgetsAdds a child widget.- Specified by:
addin interfaceHasWidgets- Parameters:
w- the widget to be added
-
add
Adds a widget to the panel. If the Widget is already attached, it will be moved to the right-most index.- Parameters:
child- the widget to be addedtext- the text to be shown on its tab
-
add
Adds a widget to the panel. If the Widget is already attached, it will be moved to the right-most index.- Parameters:
child- the widget to be addedtext- the text to be shown on its tabasHtml-trueto treat the specified text as HTML
-
add
Adds a widget to the panel. If the Widget is already attached, it will be moved to the right-most index.- Parameters:
child- the widget to be addedtab- the widget to be placed in the associated tab
-
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
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
-
clear
public void clear()Description copied from interface:HasWidgetsRemoves all child widgets.- Specified by:
clearin interfaceHasWidgets
-
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:
-
getAnimationDuration
public int getAnimationDuration()Get the duration of the animated transition between tabs.- Returns:
- the duration in milliseconds
-
getSelectedIndex
public int getSelectedIndex()Gets the index of the currently-selected tab.- Returns:
- the selected index, or
-1if none is selected.
-
getTabWidget
Gets the widget in the tab at the given index.- Parameters:
index- the index of the tab to be retrieved- Returns:
- the tab's widget
-
getTabWidget
Convenience overload to allowIsWidgetto be used directly. -
getTabWidget
Gets the widget in the tab associated with the given child widget.- Parameters:
child- the child whose tab is to be retrieved- Returns:
- the tab's widget
-
getWidget
Returns the widget at the given index.- Specified by:
getWidgetin interfaceIndexedPanel- Parameters:
index- the child widget's index- Returns:
- the child widget
-
getWidgetCount
public int getWidgetCount()Returns the number of tabs and widgets.- Specified by:
getWidgetCountin interfaceIndexedPanel- Returns:
- the number of children
-
getWidgetIndex
Convenience overload to allowIsWidgetto be used directly.- Specified by:
getWidgetIndexin interfaceIndexedPanel.ForIsWidget
-
getWidgetIndex
Returns the index of the given child, or -1 if it is not a child.- Specified by:
getWidgetIndexin interfaceIndexedPanel- Parameters:
child- the widget to be found- Returns:
- the widget's index, or
-1if it is not a child of this panel
-
insert
Convenience overload to allowIsWidgetto be used directly. -
insert
Convenience overload to allowIsWidgetto be used directly. -
insert
Convenience overload to allowIsWidgetto be used directly. -
insert
Convenience overload to allowIsWidgetto be used directly. -
insert
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 addedbeforeIndex- the index before which it will be inserted
-
insert
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 addedtext- the text to be shown on its tabasHtml-trueto treat the specified text as HTMLbeforeIndex- the index before which it will be inserted
-
insert
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 addedtext- the text to be shown on its tabbeforeIndex- the index before which it will be inserted
-
insert
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 addedtab- the widget to be placed in the associated tabbeforeIndex- the index before which it will be inserted
-
isAnimationVertical
public boolean isAnimationVertical()Check whether or not transitions slide in vertically or horizontally. Defaults to horizontally.- Returns:
- true for vertical transitions, false for horizontal
-
iterator
Description copied from interface:HasWidgetsGets an iterator for the contained widgets. This iterator is required to implementIterator.remove().- Specified by:
iteratorin interfaceHasWidgets- Specified by:
iteratorin interfaceIterable<Widget>
-
remove
public boolean remove(int index) Description copied from interface:IndexedPanelRemoves the widget at the specified index.- Specified by:
removein interfaceIndexedPanel- Parameters:
index- the index of the widget to be removed- Returns:
falseif the widget is not present
-
remove
Description copied from interface:HasWidgetsRemoves a child widget.- Specified by:
removein interfaceHasWidgets- Parameters:
w- the widget to be removed- Returns:
trueif the widget was present
-
selectTab
public void selectTab(int index) Programmatically selects the specified tab and fires events.- Parameters:
index- the index of the tab to be selected
-
selectTab
public void selectTab(int index, boolean fireEvents) Programmatically selects the specified tab.- Parameters:
index- the index of the tab to be selectedfireEvents- true to fire events, false not to
-
selectTab
Convenience overload to allowIsWidgetto be used directly. -
selectTab
Convenience overload to allowIsWidgetto be used directly. -
selectTab
Programmatically selects the specified tab and fires events.- Parameters:
child- the child whose tab is to be selected
-
selectTab
Programmatically selects the specified tab.- Parameters:
child- the child whose tab is to be selectedfireEvents- true to fire events, false not to
-
setAnimationDuration
public void setAnimationDuration(int duration) Set the duration of the animated transition between tabs.- Parameters:
duration- the duration in milliseconds.
-
setAnimationVertical
public void setAnimationVertical(boolean isVertical) Set whether or not transitions slide in vertically or horizontally.- Parameters:
isVertical- true for vertical transitions, false for horizontal
-
setTabHTML
Sets a tab's HTML contents. Use care when setting an object's HTML; it is an easy way to expose script-based security problems. Consider usingsetTabHTML(int, SafeHtml)orsetTabText(int, String)whenever possible.- Parameters:
index- the index of the tab whose HTML is to be sethtml- the tab's new HTML contents
-
setTabText
Sets a tab's text contents.- Parameters:
index- the index of the tab whose text is to be settext- the object's new text
-