Class WTabWidget


public class WTabWidget
extends WCompositeWidget
A widget that organizes contents in tab panes.

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)

  • Constructor Details

  • Method Details

    • addTab

      public WMenuItem addTab​(WWidget child, java.lang.CharSequence label, ContentLoading loadPolicy)
      Adds a new tab, with child as content, and the given label.

      Returns the menu item that implements the tab item.

    • addTab

      public final WMenuItem addTab​(WWidget child, java.lang.CharSequence label)
      Adds a new tab, with child as content, and the given label.

      Returns addTab(child, label, ContentLoading.Lazy)

    • insertTab

      public WMenuItem insertTab​(int index, WWidget child, java.lang.CharSequence label, ContentLoading loadPolicy)
      Inserts a new tab, with child as content, and the given label.

      Returns the menu item that implements the tab item.

    • insertTab

      public final WMenuItem insertTab​(int index, WWidget child, java.lang.CharSequence label)
      Inserts a new tab, with child as content, and the given label.

      Returns insertTab(index, child, label, ContentLoading.Lazy)

    • removeTab

      public WWidget removeTab​(WWidget child)
      Removes a tab item.

      See Also:
      WMenu.removeItem(WMenuItem item)
    • getCount

      public int getCount()
      Returns the number of tabs.
    • getWidget

      public WWidget getWidget​(int index)
      Returns the content widget at the given tab index.
    • getItemAt

      public WMenuItem getItemAt​(int index)
      Returns the item at the given tab index.
    • getIndexOf

      public int getIndexOf​(WWidget widget)
      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

      public void setCurrentWidget​(WWidget widget)
      Activates the tab showing the given widget
    • getCurrentWidget

      public WWidget getCurrentWidget()
      Returns the widget of the activated tab.
    • getCurrentItem

      public WMenuItem 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 by closeTab().

      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.

      See Also:
      setTabCloseable(int index, boolean closeable)
    • setTabText

      public void setTabText​(int index, java.lang.CharSequence label)
      Changes the label for a tab.
    • getTabText

      public WString getTabText​(int index)
      Returns the label for a tab.

      See Also:
      setTabText(int index, CharSequence label)
    • 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

      public WString getTabToolTip​(int index)
      Returns the tooltip for a tab.

      See Also:
      setTabToolTip(int index, CharSequence tip)
    • 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 the basePath , 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.

      Calls setInternalPathEnabled("")

    • 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.

      See Also:
      setInternalPathEnabled(String basePath), getInternalBasePath()
    • getInternalBasePath

      public java.lang.String getInternalBasePath()
      Returns the internal base path.

      The default value is the application's internalPath (WApplication.getInternalPath()) that was recorded when setInternalPathEnabled() was called, and together with each WMenuItem.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

      public Signal1<java.lang.Integer> 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 at index.

      A tab that has been closed is marked as hidden, but not removed from the menu.

      See Also:
      removeTab(WWidget child), setTabHidden(int index, boolean hidden)
    • tabClosed

      public Signal1<java.lang.Integer> tabClosed()
      Signal emitted when the user closes a tab.

      The index of the closed tab is passed as an argument.

      See Also:
      closeTab(int index), setTabCloseable(int index, boolean closeable)
    • getContentsStack

      public WStackedWidget 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​(Overflow value, java.util.EnumSet<Orientation> orientation)
      Sets how overflow of contained children must be handled.
    • setOverflow

      public final void setOverflow​(Overflow value, Orientation orientatio, Orientation... orientation)
      Sets how overflow of contained children must be handled.

      Calls setOverflow(value, EnumSet.of(orientatio, orientation))

    • setOverflow

      public final void setOverflow​(Overflow value)
      Sets how overflow of contained children must be handled.

      Calls setOverflow(value, EnumSet.of (Orientation.Horizontal, Orientation.Vertical))