TabbedPane
The TabbedPane
class provides a compact and organized way of displaying content that is divided into multiple sections, each associated with a Tab
. Users can switch between these sections by clicking on the respective tabs, often labeled with text and/or icons. This class simplifies the creation of multifaceted interfaces where different content or forms need to be accessible but not simultaneously visible.
Usages
The TabbedPane
class is a gives developers a powerful tool for organizing and presenting multiple tabs or sections within a UI. Here are some typical scenarios where you might utilize a TabbedPane
in your application:
-
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:: Utilize a
TabbedPane
to organize data management tasks, for instance:- Different dataset to be displayed in an application
- Various user profiles can be displayed within separate tabs
- Different profiles in a user management system
-
Module Selection: A
TabbedPane
can represent different modules or sections. Each tab can encapsulate the functionalities of a specific module, enabling users to focus on one aspect of the application at a time. -
Task Management: Task management applications can use a
TabbedPane
to 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 application that needs to run various programs, a
TabbedPane
could:- Serve as a sidebar which allows for different applications or programs to be run within a single application, such as what is shown in the
AppLayout
template - Create a top bar which can serve a similar purpose, or represent sub-applications within an already selected application.
- Serve as a sidebar which allows for different applications or programs to be run within a single application, such as what is shown in the
Tabs
Tabs are UI elements that can be added to tabbed panes to organize and switch between different content views.
Tabs are not intended to be used as standalone components. They are meant to be used in conjunction with tabbed panes. This class is not a Component
and should not be used as such.
Properties
Tabs are comprised of the following properties, which are then used when adding them in a TabbedPane
. These properties have getters and setters to facilitate customization within a TabbedPane
.
-
Key(
Object
): Represents the unique identifier for theTab
. -
Text(
String
): The text that will be displayed as a title for theTab
within theTabbedPane
. This is also referred to as the title via thegetTitle()
andsetTitle(String title)
methods. -
Tooltip(
String
): The tooltip text that is associated with theTab
, which will be displayed when the cursor hovers over theTab
. -
Enabled(
boolean
): Represents whether theTab
is currently enabled or not. Can be modified with thesetEnabled(boolean enabled)
method. -
Closeable(
boolean
): Represents whether theTab
can be closed. Can be modified with thesetCloseable(boolean enabled)
method. This will add a close button on theTab
which can be clicked on by the user, and fires a removal event. TheTabbedPane
component 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 aTab
to further clarify intended meaning to users. You can add a component to theprefix
slot of aTab
during 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 aTab
to theTabbedPane
with the specifiedString
as the text of theTab
.addTab(Tab tab)
- Adds theTab
provided as a parameter to theTabbedPane
.addTab(String text, Component component)
- Adds aTab
with the givenString
as the text of theTab
, and the providedComponent
displayed in the content section of theTabbedPane
.addTab(Tab tab, Component component)
- Adds the providedTab
and displays the providedComponent
in the content section of theTabbedPane
.add(Component... component)
- Adds one or moreComponent
instances to theTabbedPane
, creating a discreteTab
for 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 the component.getName()
on the passed argument.
Inserting a Tab
In addition to adding a Tab
at the end of the existing tabs, it is 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 aTab
into theTabbedPane
at the given index with the specifiedString
as the text of theTab
.insertTab(int index, Tab tab)
- Inserts theTab
provided as a parameter to theTabbedPane
at the specified index.insertTab(int index, String text, Component component)
- Inserts aTab
with the givenString
as the text of theTab
, and the providedComponent
displayed in the content section of theTabbedPane
.insertTab(int index, Tab tab, Component component)
- Inserts the providedTab
and displays the providedComponent
in 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 aTab
from theTabbedPane
by passing the Tab instance to be removed.removeTab(int index)
- Removes aTab
from theTabbedPane
by specifying the index of theTab
to 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 do not 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 is 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 is 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 application, but can also be configured via a built-in method to support mouse swiping. Both swiping and mouse swipping are disabled by default, but can be enabled with the setSwipable(boolean)
and setSwipableWithMouse(boolean)
methods, respectively.
Tab placement
The Tabs
within a TabbedPane
can be placed in various positions within the component based on the application 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
- Java
Alignment
In addition to changing the placement of the Tab
elements within the TabbedPane
, it is 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
- 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 a developer 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
- Java
Activation modes
For more fine-grained control over how the TabbedPane
behaves when being navigated by the keyboard, 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 will not show until the user presses space or enter.
Show Code
- 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 is up to the developer to handle this event in whatever way they choose. -
Auto
: Alternatively,AUTO
can be used which will fire the event, and also remove theTab
from the component for the developer, removing the need for the developer to implement this behavior manually.
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
- Java
Shadow parts
These are the various parts of the shadow DOM for the component, which will be required when styling via CSS is desired.
Slots
Listed below are the slots available for utilization within the Button
component. These slots act as placeholders within the component that control where the children of a customized element should be inserted within the shadow tree.
CSS properties
These are the various CSS properties that are used in the component, with a short description of their use.
Reflected attributes
The reflected attributes of a component will be shown as attributes in the rendered HTML element for the component in the DOM. This means that styling can be applied using these attributes.
Dependencies
This component relies on the following components - see the related article for more detailed styling information:
Best practices
The following practices are recommended for utilizing the TabbedPane
within applications:
-
Logical Grouping: Use tabs to logically group related content
- Each tab should represent a distinct category or functionality within your application
- 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
- Utilize icons and distinct colors where applicable
-
Keyboard Navigation Use webforJ's
TabbedPane
keyboard navigation support to make interaction with theTabbedPane
more seamless and intuitive for the end user -
Default Tab: If the default tab is not placed at the beginning of the
TabbedPane
, consider setting this tab as default for essential or commonly used information.