|
|
||
Kirill Grouchnikov's BlogSpicing up your JTabbedPane - part IIIPosted by kirillcool on March 14, 2006 at 01:23 PM | Comments (0)This is the third part of the series that describes the additional capabilities that you can get on your tabbed panes once you start using the Substance look-and-feel. The first part described close buttons and animation on modified tabs, while the second part described vetoable close buttons and vertical tabs. This entry describes new features available in the next version of Substance (code-named Firenze, currently available in development status). The first addition is single-click close of multiple tabs. This functionality borrows from both NetBeans (Alt+Click on close button closes all tabs but this, Shift+Click on close button closes all tabs) and Firefox (middle click closes tab). The logic that decides what tabs to close is written by the application and set on the corresponding tabbed pane. Substance tracks down mouse events on the relevant tabs, calls the application callback and closes the tabs specified by the application. Here is the example code to clarify this capability. Application needs to implement the TabCloseCallback interface which contains the following four functions:
public TabCloseKind onAreaClick(JTabbedPane tabbedPane, int tabIndex,
The first two functions are called when the user clicks on either the tab itself or on its close button (if specified). TabCloseKind is an enum with the following values:
public enum TabCloseKind {
The last two functions are used to provide tooltips to instruct the user about the application-specific behaviour of single-click tab close. Sample implementation of this interface is:
TabCloseCallback closeCallbackMain = new TabCloseCallback() {
Here, simple click on close button closes the relevant tab, alt-click on close button close all tabs but the clicked one and shift-click on close button closes all tabs. In addition, we have the matching tooltip message when the mouse hovers over the close button:
Furthermore, middle click on the tab close that tab and shift-middle-click closes all tabs. The last line associates our tab-close callback with one of our tabbed panes. In order to match the multiple-tabs close, the option to veto the tab close has been augmented with VetoableMultipleTabCloseListener interface - see the test application for the sample usage. The second major enhancement to the tabbed panes was requested by one of the users. This enhancement allows to specify custom alignment of tab texts on left and right placement. The default Swing behaviour is center-alignment, which can lead to unfriendly "fir-like" zigzags on tabs with varying text lengths:
In order to overcome this behaviour and allow applications to show left or right aligned texts, Substance provides the following enum:
public enum TabTextAlignmentKind {
The values are:
Screenshot of FOLLOW_ORIENTATION in RTL-oriented application with RIGHT placement:
Stay tuned for the next part of this series - much more to come. Bookmark blog post: CommentsComments are listed in date ascending order (oldest first) | Post Comment | ||
|
|