views:

193

answers:

2

Is it possible to capture the close tab event for a JTabbedPanel in Java Swing.

I want to check for some conditions and if they are not met, then I have to prevent the user from closing it.

Thanks!

Update: I created a custom event, based on this code and it solved my problem.

+1  A: 

Sun's tutorial on Tabbed Panes has an example with close buttons on each tab. If you look a the source of the example you can see it reacting to the close clicked.

Edit: ButtonTabComponent. It has an inner class that extends JButton. Based on your comment, do you already have something in place that closes Tabs? What are you doing to achieve this?

unholysampler
I checked out this tutorial. But I couldn't find the place whether it captures the close event.
Sudar
See edit for direct link to the source and an additional question for clarification.
unholysampler
There is not "close event". The code to close the tab is in the ActionListener that was added to the close button on the tab If you don't want to close the tab when the close icon is clicked then add your code to the ActionListener.
camickr
A: 

I created a custom event, based on this code and it solved my problem.

Sudar