Click here to Skip to main content
15,891,943 members
Articles / Programming Languages / Java / Java SE

JTabbedPane with Closing Tabs

Rate me:
Please Sign up or sign in to vote.
3.40/5 (11 votes)
12 Aug 2010CPOL2 min read 96.9K   4K   21  
This article illustrates a simple way to have closing tabs without diving into BasicTabbedPaneUI.
package tabbedpane;
import java.awt.Graphics;
import javax.swing.*;


public class CloseTabbedPane extends JTabbedPane{
	private TabCloseUI closeUI;
	public CloseTabbedPane(){			
		addTab("TAB 1 ", new JPanel());
		closeUI = new TabCloseUI();
		closeUI.setTabbedPane(this);
		addMouseMotionListener(closeUI);
		addMouseListener(closeUI);
	}

	public void paint(Graphics g){
		super.paint(g);
		closeUI.paint(g);
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Canada Canada
Master of Computer and Information Science: Graduated from American University of Armenia.
Bachelor of Engineering (Management Systems): Graduated from State Engineering University of Armenia.

Comments and Discussions