25 Ocak 2009 Pazar

The Easiest Java Tab Implementation With Close Button

Unfortunately, the current implementation of JTabbedPane class in Swing API does not contain a close button. You have to implement this feature by yourself. Here, I have a simple JTabbedPane implementation with a close button. I used MetalIconFactory.InternalFrameCloseIcon class in the close button. Because this is a private inner class, you need to use MetalIconFactory.getInternalFrameCloseIcon(int iconSize). Check the following screenshots to see how a JTabbedPane and a CloseButtonTabbedPane looks like:

A tabbed pane with default JTabbedPane implementation, shows up as below:

A tabbed pane with CloseButtonTabbedPane implementation, shows up as below:

Click here to download the source code of CloseButtonTabbedPane here.

The advantages of this implementation is:
  • You don't need an image for close button. Instead you use an image provided by Java API.
  • Everything you need is packaged inside just 1 class.

Hiç yorum yok: