TabbedPane
Multiple sections of content can be organized under a single TabbedPane, where each section is tied to a clickable Tab. Only one section is visible at a time, and tabs can display text, icons, or both to help users navigate between them.
Usages
The TabbedPane class gives developers a powerful tool for organizing and presenting multiple tabs or sections within a UI. Here are some typical scenarios where you might use a TabbedPane in your app:
-
Document Viewer: Implementing a document viewer where each tab represents a different document or file. Users can easily switch between open documents for efficient multitasking.
-
Data Management: Use a
TabbedPaneto organize data management tasks, for instance:- Different datasets to be displayed in an app
- Various user profiles can be displayed within separate tabs
- Different profiles in a user management system
-
Module Selection: A
TabbedPanecan represent different modules or sections. Each tab can encapsulate the functionalities of a specific module, enabling users to focus on one aspect of the app at a time. -
Task Management: Task management apps can use a
TabbedPaneto represent various projects or tasks. Each tab could correspond to a specific project, allowing users to manage and track tasks separately. -
Program Navigation: Within an app that needs to run various programs, a
TabbedPanecould:- Serve as a sidebar which allows for different apps or programs to be run within a single app, such as what's shown in the
AppLayouttemplate - Create a top bar which can serve a similar purpose, or represent sub-applications within an already selected app
- Serve as a sidebar which allows for different apps or programs to be run within a single app, such as what's shown in the
Tabs dwc-tab
Tabs are UI elements that can be added to tabbed panes to organize and switch between different content views.
Tabs aren't intended to be used as standalone components. They're meant to be used in conjunction with tabbed panes. This class isn't a Component and shouldn't be used as such.
Properties
Tabs are composed of the following properties, which are used when adding them in a TabbedPane. These properties have getters and setters to facilitate customization within a TabbedPane.
-
Text(
String): The text that's displayed as a title for theTabwithin theTabbedPane. This is also referred to as the title via thegetTitle()andsetTitle(String title)methods. -
Tooltip(
String): The tooltip text associated with theTab, which is displayed when the cursor hovers over theTab. -
Enabled(
boolean): Represents whether theTabis enabled or not. Can be modified with thesetEnabled(boolean enabled)method. -
Closable(
boolean): Represents whether theTabcan be closed. Can be modified with thesetClosable(boolean closable)method. This will add a close button on theTabwhich can be clicked, and fires a removal event. TheTabbedPanecomponent dictates how to handle the removal. -
Slot(
Component): Slots provide flexible options for improving the capability of aTab. You can have icons, labels, loading spinners, clear/reset capability, avatar/profile pictures, and other beneficial components nested within aTabto further clarify intended meaning to users. You can add a component to theprefixslot of aTabduring construction. Alternatively, you can use thesetPrefixComponent()andsetSuffixComponent()methods to insert various components before and after the displayed option within aTab.TabbedPane pane = new TabbedPane();pane.addTab(new Tab("Documents", TablerIcon.create("files")));
Tab manipulation
Various methods exist to allow developers to add, insert, remove, and manipulate various properties of Tab elements within the TabbedPane.
Adding a Tab
The addTab() and add() methods exist in different overloaded capacities to allow developers flexibility in adding new tabs to the TabbedPane. Adding a Tab will place it after any previously existing tabs.
addTab(String text): adds aTabto theTabbedPanewith the specifiedStringas the text of theTab.addTab(Tab tab): adds theTabprovided as a parameter to theTabbedPane.addTab(String text, Component component): adds aTabwith the givenStringas the text of theTab, and the providedComponentdisplayed in the content section of theTabbedPane.addTab(Tab tab, Component component): adds the providedTaband displays the providedComponentin the content section of theTabbedPane.add(Component... component): adds one or moreComponentinstances to theTabbedPane, creating a discreteTabfor each one, with the text being set to the name of theComponent.
The add(Component... component) determines the name of the passed Component by calling component.getName() on the passed argument.
Inserting a Tab
In addition to adding a Tab at the end of the existing tabs, it's also possible to create a new one at a designated position. To do this, multiple overloaded versions of the insertTab().
insertTab(int index, String text): inserts aTabinto theTabbedPaneat the given index with the specifiedStringas the text of theTab.insertTab(int index, Tab tab): inserts theTabprovided as a parameter to theTabbedPaneat the specified index.insertTab(int index, String text, Component component): inserts aTabwith the givenStringas the text of theTab, and the providedComponentdisplayed in the content section of theTabbedPane.insertTab(int index, Tab tab, Component component): inserts the providedTaband displays the providedComponentin the content section of theTabbedPane.
Removing a Tab
To remove a single Tab from the TabbedPane, use one of the following methods:
removeTab(Tab tab): removes aTabfrom theTabbedPaneby passing the Tab instance to be removed.removeTab(int index): removes aTabfrom theTabbedPaneby specifying the index of theTabto be removed.
In addition to the two above methods for removal of a single Tab, use the removeAllTabs() method to clear the TabbedPane of all tabs.
The remove() and removeAll() methods don't remove tabs within the component.
Tab/Component association
To change the Component to be displayed for a given Tab, call the setComponentFor() method, and pass either the instance of the Tab, or the index of that Tab within the TabbedPane.
If this method is used on a Tab that's already associated with a Component, the previously associated Component will be destroyed.
Configuration and layout
The TabbedPane class has two constituent parts: a Tab that's displayed in a specified location, and a component to be displayed. This can be a single component, or a Composite component, allowing for the display of more complex components within a tab's content section.
Swiping
The TabbedPane supports navigating through the various tabs via swiping. This is ideal for a mobile app, but can also be configured via a built-in method to support mouse swiping. Both swiping and mouse swiping are disabled by default, but can be enabled with the setSwipeable(boolean) and setSwipeWithMouse(boolean) methods, respectively.
Tab placement
The Tabs within a TabbedPane can be placed in various positions within the component based on the app developers preference. Provided options are set using the provided enum, which has the values of TOP, BOTTOM, LEFT, RIGHT, or HIDDEN. The default setting is TOP.
Show Code
- TabbedPanePlacementView.java
Alignment
In addition to changing the placement of the Tab elements within the TabbedPane, it's also possible to configure how the tabs will align within the component. By default, the setting AUTO is in effect, which allows the placement of the tabs to dictate their alignment.
The other options are START, END, CENTER, and STRETCH. The first three describe the position relative to the component, with STRETCH making the tabs fill the available space.
Show Code
- TabbedPaneAlignmentView.java
Border and activity indicator
The TabbedPane will have a border displayed for the tabs within it by default, placed dependant on which Placement has been set. This border helps to visualize the space that the various tabs within the pane take up.
When a Tab is clicked on, by default, an activity indicator is displayed near that Tab to help highlight which is the currently selected Tab.
Both of these options can be customized by changing the boolean values using the appropriate setter methods. To change whether or not the border is shown, the setBorderless(boolean) method can be used, with true hiding the border, and false, the default value, displaying the border.
This border doesn't apply to the entirety of the TabbedPane component, and merely serves as a separator between the tabs and the content of the component.
To set the visibility of the active indicator, the setHideActiveIndicator(boolean) method can be used. Passing true to this method will hide the active indicator beneath an active Tab, whereas false, the default, keeps the indicator displayed.
Show Code
- TabbedPaneBorderView.java
Activation modes
For more fine-grained control over how the TabbedPane behaves with keyboard navigation, the Activation mode can be set to specify how the component should behave.
-
Auto: when set to auto, navigating tabs with the arrow keys will instantly show the corresponding tab component. -
Manual: when set to manual, the tab will receive focus but won't show until the user presses space or enter.
Show Code
- TabbedPaneActivationView.java
Removal options
Individual Tab elements can be set to be closable. Closable tabs will have a close button added to the tab, which fires a close event when clicked. The TabbedPane dictates how this behavior is handled.
-
Manual: by default, removal is set toMANUAL, which means that the event is fired, but it's up to the developer to handle this event in whatever way they choose. -
Auto: alternatively,AUTOcan be used which will fire the event, and also remove theTabfrom the component for the developer, removing the need for the developer to implement this behavior manually.
Segment control 26.00
The TabbedPane can be rendered as a segment control by enabling the segment property with setSegment(true). In this mode, tabs are displayed with a sliding pill indicator that highlights the active selection, providing a compact alternative to the standard tabbed interface.
Show Code
- TabbedPaneSegmentView.java
Styling
Expanse and theme
The TabbedPane comes with built-in Expanse and Theme options similar to other webforJ components. These can be used to quickly add styling that conveys various meaning to the end user without needing to style the component with CSS.
Show Code
- TabbedPaneExpanseThemeView.java
Best practices
The following practices are recommended for using the TabbedPane within applications:
-
Logical Grouping: Use tabs to logically group related content:
- Each tab should represent a distinct category or functionality within your app.
- Group similar or logical tabs near one another.
-
Limited Tabs: Avoid overwhelming users with too many tabs. Consider using a hierarchical structure or other navigation patterns where applicable for a clean interface.
-
Clear Labels: Clearly label your Tabs for intuitive use:
- Provide clear and concise labels for each tab.
- Labels should reflect the content or purpose, making it easy for users to understand.
- Use icons and distinct colors where applicable.
-
Keyboard Navigation: Use webforJ's
TabbedPanekeyboard navigation support to make interaction with theTabbedPanemore seamless and intuitive for the end user. -
Default Tab: If the default tab isn't placed at the beginning of the
TabbedPane, consider setting this tab as default for essential or commonly used information.