What Is It

The BoxTabbedPaneUI a new TabbedPaneUI that resembles Safari's browser tabs.

How To Use It

This demo is set up as follows:

JTabbedPane tabs = new JTabbedPane();
tabs.setUI(new BoxTabbedPaneUI());
tabs.putClientProperty(BoxTabbedPaneUI.PROPERTY_CLOSEABLE_TABS, isCloseable);
tabs.putClientProperty(BoxTabbedPaneUI.PROPERTY_HIDE_SINGLE_TAB, isHideSingleTab);
tabs.putClientProperty(BoxTabbedPaneUI.PROPERTY_TRAILING_COMPONENTS, Arrays.asList(addButton));

 // to prep the addButton look and feel:
addButton.setMargin(new Insets(0, 0, 0, 0));
BoxTabbedPaneUI.getStyle(tabs).formatControlRowButton(tabs, addButton, -1);

How It Works

Unfortunately I wasn't able to extend the BasicTabbedPaneUI class. (It's always best to extend the basic class if you can! They handle so many small details its easy to forget.) So this is a built-from-scratch subclass of the TabbedPaneUI. This does not support the tab layout policy attribute: you get one row of tabs and nothing else.

The row of tabs is displayed using a SplayedLayout, which means several tabs may be squished together; but if you mouse over a tab it regains its preferred size.

This demo features a close button for the tabs, but you have complete control over the tab as a JComponent. For example: you could use a text field to let the user change the document name. You could add a throbber or a CircularProgressBarUI slider to indicate a document is loading. These days browsers may add a sound icon if a tab is playing audio. As I write this in Eclipse I notice my tabs also have a file icon which varies depending on the file type of the tab. Tabs have come a long way since Swing was first conceived; a good UI might find some additional features/feedback to add to its tabs.

The javadoc describes several client properties you can use to inject control over how components are configured. (For example: you could change the background color, the border, etc.)

Discussion

I recommend using the default TabbedPaneUI if you have a fix number of tabs, and if you're confident that 95% of the time they're going to be displayed in one row. For example: if you've designed a dialog box and you have a predefined number of tabs ("Login Options", "Desktop Options", "Security", etc.).

But if you have a user-defined (unknown) number of tabs: that's where a tab UI like this helps. This is intended to be used for a tabbed document interface ("TDI", or "MDI" for "Multiple Document Interface").

There is a lot of related reading on this online and in well-researched books like About Face. To sum up what I've read so far: