JTabbedPane, if all the tabs will
not fit within a single tab run, the JTabbedPane
will wrap tabs onto multiple runs. There have been many requests
to provide an alternative scheme, where the JTabbedPane
would instead display a single, scrollable run of tabs.
This proposal outlines a new api for providing such
scrollable tab support in JTabbedPane for the merlin release.
The bugtraq report that corresponds to this change is:
4093898.
However, the problem with multiple runs is in handling the case where the user selects a tab in a run which is not adjacent to the panel display area. For the Windows and Motif look&feel implementations, this action will cause the runs to rotate such that the run containing the selected tab is placed adjacent to the panel display area.
This behavior can be extremely disorienting to the user because it constantly re-arranges the tabs, eliminating predictability in the UI. The Metal look&feel solved this problem by always leaving the runs fixed, even if the selected tab is not adjacent to the panel display area:
Unfortunately the downside of the Metal solution is that it visually departs from the 'tabbed folder' metaphor (the selected tab is not 'attached' to its content). In fact, Chapter 7 of the Java Look and Feel Guidelines recommends against creating tabbed panes with multiple runs:
"If your tabbed pane requires multiple rows of tabs, consider dividing the content among several dialog boxes or components. Multiple rows of tabs can be confusing."
While contraining tabs in a tabbed pane to a number which will fit within a single run is an important UI guideline, there are circumstances where a proliferation of tabs cannot be avoided. This is often the case if the tabs are created dynamically by the application at runtime (perhaps driven off the content of a database).
An alternate solution for handling the tab proliferation case is to constrain the tabbed pane to a single, scrollable run of tabs:
Naturally, this solution has its own set of usability problems, the most obvious of which is that the user can no longer view all possible selections at one time. However, this scrollable-tab behavior is becoming increasingly common in user interfaces and therefore Swing should support it as an option.
JTabbedPane APIJTabbedPane:
/**
* Sets the policy which the tabbedpane will use in laying out the tabs
* when all the tabs will not fit within a single run.
* Possible values are:
* o JTabbedPane.WRAP_TAB_LAYOUT
* o JTabbedPane.SCROLL_TAB_LAYOUT
*
* The default value, if not set, is JTabbedPane.WRAP_TAB_LAYOUT.
*
* @param layoutPolicy the policy used to layout the tabs
* @exception IllegalArgumentException if layoutPolicy value isn't one
* of the above valid values
* @see #getTabLayoutPolicy
* @since 1.4
*
* @beaninfo
* preferred: true
* bound: true
* attribute: visualUpdate true
* enum: WRAP_TAB_LAYOUT JTabbedPane.WRAP_TAB_LAYOUT
* SCROLL_TAB_LAYOUT JTabbedPane.SCROLL_TAB_LAYOUT
* description: The tabbedpane's policy for laying out the tabs
*
*/
public void setTabLayoutPolicy(int layoutPolicy)
/**
* Returns the policy used to layout tabs for this tabbedpane.
* @see #setTabLayoutPolicy
* @since 1.4
*/
public boolean getTabLayoutPolicy()
Additionally, constants for the supported policy values will be added to
JTabbedPane:
/**
* The tab layout policy for wrapping tabs in multiple runs when all
* tabs will not fit within a single run.
*/
public static final int WRAP_TAB_LAYOUT = 0;
/**
* The tab layout policy for providing a scrollable region of tabs
* when all the tabs will not fit within a single run. A pair of
* scroll buttons are provided for the user to control the scrolling.
* The placement of the scroll buttons is determined by the look&feel.
*/
public static final int SCROLL_TAB_LAYOUT = 1;
tabLayoutPolicy property will be WRAP_TAB_LAYOUT
which matches the current layout behavior of the tabbed pane.