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?

6/28/2013 6:21:16 PM

You can try onCloseRequest for Tab class

tab.setOnCloseRequest(new EventHandler<Event>()
    public void handle(Event arg0) 
        //your code
8/6/2016 4:40:03 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow