Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/xeno04/ on line 14
Walker Software Weblog: JTabbedPane with a Close Button

JTabbedPane with a Close Button

Mar 9, 04:47 PM

For some of my work, I often need a JTabbedPane with a close button. Many of those I found were either not free and usually completely custom components that only look right on Windows or with their bundled look and feel. So far, the “best” code I’ve found is from a javaworld article. But it has it’s own problem’s.

First, It doesn’t take on the LAF of the program. I set out to fix this by creating a proxy for the UI classes in involved only to find out that 1) the base interface of Tabbed Pane UI is unusable 2) Apple did not subclass the Metal (or Basic, I forget which) LAF, they copied it and sub-classed the copy. But, the code from the article implements a tab that looks like Eclipse 2.0. Not the best, but it looks good on Mac and Windows (esp. using the Alloy LAF). If we are going to emulate Eclipse, I’d rather do 3.0 — but not so much that I felt like rewriting the code. Of course, I could just switch it SWT, but I’ve got a lot of code written for swing.

Second, the code uses some undocumented code from other look and feels which no longer work correctly on modern Windows JRE (found that during beta testing). I hacked the code to use an icon for Eclipse 3.0 for it’s close button instead.

Third, it’s got some funky size issues with Mac OS X. For the Windows version of the App, we use Incors Alloy Look and Feel¬†with the Glass Theme (note: Alloy is not free, but it is worth the money — at least for me). Mainly because Alloy is close enough to Aqua, and the first series screen-shots sent to the client were Aqua. Also Alloy, unlike JGoodies, looks as good on the Mac as it does on Windows. Simply using Alloy as the LAF (as opposed testing the OS and leaving the default LAF on Mac like I normally do) solved the issue. I’d like to find and fix the real cause, but I was strapped for time and I’m getting a few doubts about Apple’s Swing implementation.

Anywho, after I get a chance to clean up the code, I may post my changes to code here. I’d like to experiment with some 3rd-party proxy libs to see if I can get it use the App’s look and feel.

Link to Part 2 of this article.


Your article sounds interesting. With which version of the jvm is it compatible? I found a forum listing at and they suggest two approaches.

One of them is dependent on 1.5 and I can\'t use that because I need to be compatible with 1.4, and the other is generating an ArrayIndexOutOfBoundsError when more than 1 pane is present. The error is in javax.swing.plaf.basic.BasicTabbedPaneUI.paintTabArea(
and I\'m reluctant to mess around with the base java libraries.

Anyway, I\'d be very interested when you post your code.

— Ganesh Shankar · Jul 7, 06:59 PM · #

The source code is at It is basically to same code that we both linked to, but modified to run on JVM after 1.3 (because is doesn\'t rely the implementation of the windows look and feel. The included icon is from eclipse 3.X. I\'ve also tweak the drawing a little and completely disabled the \"Maximize\" button. One of these days, I would like to write replacement of Tabbed Pane that is broken into separate components.

— Adam · Jul 8, 02:37 PM · #

Commenting is closed for this article.