import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.stage.Stage;


public class MainClass extends Application { 
     
        public static void main(String[] arg) { 
            launch(arg); 
        } 
     
        @Override 
        public void start(Stage primaryStage) throws Exception { 
            TabPane tabPane = new TabPane(); 
            tabPane.getSelectionModel().selectedItemProperty().addListener((ov, oldTab, newTab) -> { 
                System.out.println("Tab change: " + oldTab + "/" + newTab); 
            }); 
            Tab tab = new Tab("Test tab"); 
            tab.setOnCloseRequest((event) -> { 
                System.out.println("Removing tab"); 
                event.consume(); 
                tabPane.getTabs().remove(tab); 
            }); 
            System.out.println("Adding tab"); 
            tabPane.getTabs().add(tab); 
            Group root = new Group(tabPane); 
            Scene scene = new Scene(root); 
            primaryStage.setScene(scene); 
            primaryStage.show(); 
        } 
     
    } 