Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to restrict closing the tab in tabpane after clicking the close button.

Sai Pradeep DandemDec 23 2011 — edited Feb 12 2013
Hi all,
Greetings.
I am implementing a TabPane with different 'user form's in each Tab. And all the tabs are *'closable'*.
If the user enters some data in the form, and tries to close the tab without saving the form , i need to show a confirm dialogue box that the user should go ahead or not.
If he clicks cancel, the tab should not close.

But currently i am searching for a method something like 'setOnClosing' method for tab.
There is only tab.setOnClosed() method, which will call the event after closing the tab.

Some thing the code is like below.
tab.setOnClosed(new EventHandler<javafx.event.Event>() {
     @Override
     public void handle(javafx.event.Event e) {
	   // TODO: Actions to be taken on close of tab.
           // Logic to show the confirm dialouge box.
           //  if YES - close the tab
           //  if NO - don't close the tab.
     }
});
But my logic is executing after closing the tab. (ofcourse, as it is on setOnClosed() ;) ). Can anyone tell me how to get control before closing the tab ?

Thanks in Advance.
Sai Pradeep Dandem.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 12 2013
Added on Dec 23 2011
7 comments
4,061 views