Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confirm dialog window when closing a tab

I'm new to JavaFX. I want to create Listener which calls question dialog when user closes a tab into the TabPane. So far I managed to create tabs dynamically and add some custom configuration.

    tabAvLabel = new Label(ss);

    tabPane.getTabs().add(0, tab);  // Place the new tab always first
    tabPane.getSelectionModel().select(tab);    // Always show the new tab
    tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.ALL_TABS); // Add close button to all new tabs

I don't know what event listener I need to use and how to define it. Would you show me how to implement this?

like image 438
user1285928 Avatar asked Oct 19 '25 04:10

user1285928


1 Answers

You can try onCloseRequest for Tab class

tab.setOnCloseRequest(new EventHandler<Event>()
{
    @Override
    public void handle(Event arg0) 
    {
        //your code
    }
});
like image 114
VagrantAI Avatar answered Oct 22 '25 02:10

VagrantAI



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!