Class WTabWidget
public class WTabWidget extends WCompositeWidget
This widget combines a horizontal WMenu
with a WStackedWidget
, and a tab-like
look.
A tab widget will place the tab bar on top of the contents, and fit the contents below it.
Usage example:
WTabWidget examples = new WTabWidget(this);
examples.addTab(helloWorldExample(), "Hello World");
examples.addTab(chartExample(), "Charts");
examples.addTab(new WText("A WText"), "WText");
examples.currentChanged().addListener(this, new Signal.Listener(){
public void trigger() {
//custom code
}
});
examples.setInternalPathEnabled();
examples.setInternalBasePath("/examples");
CSS
The tab widget is styled by the current CSS theme.
An example WTabWidget (default) | An example WTabWidget (polished) |
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WTabWidget.LoadPolicy
Enumeration to indicate when the contents should be loaded.Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Constructor Summary
Constructors Constructor Description WTabWidget()
Creates a new tab widget.WTabWidget(WContainerWidget parent)
Creates a new tab widget. -
Method Summary
Modifier and Type Method Description WMenuItem
addTab(WWidget child, java.lang.CharSequence label)
Adds a new tab, with child as content, and the given label.WMenuItem
addTab(WWidget child, java.lang.CharSequence label, WTabWidget.LoadPolicy loadPolicy)
Adds a new tab, with child as content, and the given label.void
closeTab(int index)
Closes a tab atindex
.Signal1<java.lang.Integer>
currentChanged()
Signal emitted when the user activates a tab.WStackedWidget
getContentsStack()
Returns the contents stack.int
getCount()
Returns the number of tabs.int
getCurrentIndex()
Returns the index of the activated tab.WMenuItem
getCurrentItem()
Returns the item of the activated tab.WWidget
getCurrentWidget()
Returns the widget of the activated tab.int
getIndexOf(WWidget widget)
Returns the index of the tab of the given content widget.java.lang.String
getInternalBasePath()
Returns the internal base path.WMenuItem
getItemAt(int index)
Returns the item at the given tab index.WString
getTabText(int index)
Returns the label for a tab.WString
getTabToolTip(int index)
Returns the tooltip for a tab.WWidget
getWidget(int index)
Returns the content widget at the given tab index.WMenuItem
insertTab(int index, WWidget child, java.lang.CharSequence label)
Inserts a new tab, with child as content, and the given label.WMenuItem
insertTab(int index, WWidget child, java.lang.CharSequence label, WTabWidget.LoadPolicy loadPolicy)
Inserts a new tab, with child as content, and the given label.boolean
isInternalPathEnabled()
Returns whether internal paths are enabled.boolean
isTabCloseable(int index)
Returns whether a tab is closeable.boolean
isTabEnabled(int index)
Returns whether a tab is enabled.boolean
isTabHidden(int index)
Returns whether a tab is hidden.void
removeTab(WWidget child)
Removes a tab item.void
setCurrentIndex(int index)
Activates the tab at index.void
setCurrentWidget(WWidget widget)
Activates the tab showing the given widgetvoid
setInternalBasePath(java.lang.String path)
Sets the internal base path.void
setInternalPathEnabled()
Enables internal paths for items.void
setInternalPathEnabled(java.lang.String basePath)
Enables internal paths for items.void
setOverflow(WContainerWidget.Overflow value)
Sets how overflow of contained children must be handled.void
setOverflow(WContainerWidget.Overflow value, Orientation orientatio, Orientation... orientation)
Sets how overflow of contained children must be handled.void
setOverflow(WContainerWidget.Overflow value, java.util.EnumSet<Orientation> orientation)
Sets how overflow of contained children must be handled.void
setTabCloseable(int index, boolean closeable)
Make it possible to close a tab interactively or bycloseTab()
.void
setTabEnabled(int index, boolean enable)
Enables or disables a tab.void
setTabHidden(int index, boolean hidden)
Hides or shows a tab.void
setTabText(int index, java.lang.CharSequence label)
Changes the label for a tab.void
setTabToolTip(int index, java.lang.CharSequence tip)
Sets the tooltip for a tab.Signal1<java.lang.Integer>
tabClosed()
Signal emitted when the user closes a tab.Methods inherited from class eu.webtoolkit.jwt.WCompositeWidget
addStyleClass, boxBorder, boxPadding, callJavaScriptMember, doJavaScript, enableAjax, find, findById, getAttributeValue, getBaseZIndex, getClearSides, getDecorationStyle, getFloatSide, getHeight, getId, getImplementation, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getObjectName, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getTabIndex, getTakeImplementation, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, isCanReceiveFocus, isDisabled, isEnabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, load, propagateSetEnabled, propagateSetVisible, refresh, remove, removeStyleClass, render, resize, scrollVisibilityChanged, setAttributeValue, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFloatSide, setFocus, setHidden, setHiddenKeepsGeometry, setId, setImplementation, setInline, setJavaScriptMember, setLineHeight, setMargin, setMaximumSize, setMinimumSize, setObjectName, setOffsets, setPopup, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isLayoutSizeAware, isRendered, layoutSizeChanged, needsRerender, positionAt, positionAt, removeChild, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, setFormData
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
WTabWidget
Creates a new tab widget. -
WTabWidget
public WTabWidget()Creates a new tab widget.
-
-
Method Details
-
addTab
public WMenuItem addTab(WWidget child, java.lang.CharSequence label, WTabWidget.LoadPolicy loadPolicy)Adds a new tab, with child as content, and the given label.Returns the menu item that implements the tab item.
-
addTab
Adds a new tab, with child as content, and the given label.Returns
addTab(child, label, WTabWidget.LoadPolicy.LazyLoading)
-
insertTab
public WMenuItem insertTab(int index, WWidget child, java.lang.CharSequence label, WTabWidget.LoadPolicy loadPolicy)Inserts a new tab, with child as content, and the given label.Returns the menu item that implements the tab item.
-
insertTab
Inserts a new tab, with child as content, and the given label.Returns
insertTab(index, child, label, WTabWidget.LoadPolicy.LazyLoading)
-
removeTab
Removes a tab item.The widget itself is not deleted.
- See Also:
WMenu.removeItem(WMenuItem item)
-
getCount
public int getCount()Returns the number of tabs. -
getWidget
Returns the content widget at the given tab index. -
getItemAt
Returns the item at the given tab index. -
getIndexOf
Returns the index of the tab of the given content widget.If the widget is not in this tab widget, then -1 is returned.
-
setCurrentIndex
public void setCurrentIndex(int index)Activates the tab at index. -
getCurrentIndex
public int getCurrentIndex()Returns the index of the activated tab. -
setCurrentWidget
Activates the tab showing the given widget -
getCurrentWidget
Returns the widget of the activated tab. -
getCurrentItem
Returns the item of the activated tab. -
setTabEnabled
public void setTabEnabled(int index, boolean enable)Enables or disables a tab.Enables or disables the tab at
index
. A disabled tab cannot be activated. -
isTabEnabled
public boolean isTabEnabled(int index)Returns whether a tab is enabled. -
setTabHidden
public void setTabHidden(int index, boolean hidden)Hides or shows a tab.Hides or shows the tab at
index
. -
isTabHidden
public boolean isTabHidden(int index)Returns whether a tab is hidden. -
setTabCloseable
public void setTabCloseable(int index, boolean closeable)Make it possible to close a tab interactively or bycloseTab()
.A tab that has been closed is marked as hidden, but not removed from the menu.
- See Also:
removeTab(WWidget child)
-
isTabCloseable
public boolean isTabCloseable(int index)Returns whether a tab is closeable. -
setTabText
public void setTabText(int index, java.lang.CharSequence label)Changes the label for a tab. -
getTabText
Returns the label for a tab. -
setTabToolTip
public void setTabToolTip(int index, java.lang.CharSequence tip)Sets the tooltip for a tab.The tooltip is shown when the user hovers over the label.
-
getTabToolTip
Returns the tooltip for a tab. -
setInternalPathEnabled
public void setInternalPathEnabled(java.lang.String basePath)Enables internal paths for items.The menu participates in the internal path by changing the internal path when an item has been selected, and listening for path changes to react to path selections. As a consequence this allows the user to bookmark the current menu selection and revisit it later, use back/forward buttons to navigate through history of visited menu items, and allows indexing of pages.
For each menu item,
WMenuItem.getPathComponent()
is appended to thebasePath
, which defaults to the internal path (WApplication.getInternalPath()
). A '/' is appended to the base path, to turn it into a folder, if needed.By default, menu interaction does not change the application internal path.
- See Also:
WMenuItem.setPathComponent(String path)
-
setInternalPathEnabled
public final void setInternalPathEnabled()Enables internal paths for items. -
isInternalPathEnabled
public boolean isInternalPathEnabled()Returns whether internal paths are enabled.- See Also:
setInternalPathEnabled(String basePath)
-
setInternalBasePath
public void setInternalBasePath(java.lang.String path)Sets the internal base path.A '/' is appended to turn it into a folder, if needed.
-
getInternalBasePath
public java.lang.String getInternalBasePath()Returns the internal base path.The default value is the application's internalPath (
WApplication.getInternalPath()
) that was recorded whensetInternalPathEnabled()
was called, and together with eachWMenuItem.getPathComponent()
determines the paths for each item.For example, if
getInternalBasePath()
is"/examples/"
and pathComponent() for a particular item is"charts/"
, then the internal path for that item will be"/examples/charts/"
.- See Also:
setInternalPathEnabled(String basePath)
-
currentChanged
Signal emitted when the user activates a tab.The index of the newly activated tab is passed as an argument.
-
closeTab
public void closeTab(int index)Closes a tab atindex
.A tab that has been closed is marked as hidden, but not removed from the menu.
-
tabClosed
Signal emitted when the user closes a tab.The index of the closed tab is passed as an argument.
-
getContentsStack
Returns the contents stack.The tab widget is implemented as a
WMenu
+WStackedWidget
which displays the contents. This method returns a reference to this contents stack. -
setOverflow
public void setOverflow(WContainerWidget.Overflow value, java.util.EnumSet<Orientation> orientation)Sets how overflow of contained children must be handled.This is an alternative (CSS-ish) way to configure scroll bars on a container widget, compared to wrapping inside a
WScrollArea
.Unlike
WScrollArea
, horizontal scrolling does not work reliably when the container widget is inserted in a layout manager: the layout manager will overflow rather than use scrollbars for this this widget. A solution then is to useWScrollArea
instead.- See Also:
WScrollArea
-
setOverflow
public final void setOverflow(WContainerWidget.Overflow value, Orientation orientatio, Orientation... orientation)Sets how overflow of contained children must be handled.Calls
setOverflow(value, EnumSet.of(orientatio, orientation))
-
setOverflow
Sets how overflow of contained children must be handled.Calls
setOverflow(value, EnumSet.of (Orientation.Horizontal, Orientation.Vertical))
-