Here is a potential solution. If you add your own βtell the userβ logic to the code below, it should do what you want.
package com.test; import java.util.Set; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.scene.input.MouseEvent; import javafx.scene.layout.BorderPane; import javafx.scene.paint.Color; import javafx.stage.Stage; public class JavaFXApp extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("http://stackoverflow.com/questions/13538227/tab-consuming-in-tabpane-on-default-closing"); BorderPane rootPane = new BorderPane(); Scene scene = new Scene(rootPane, 640, 360, Color.WHITE); TabPane tabPane = new TabPane(); Tab tab1 = new Tab(); tab1.setText("Tab 1"); tabPane.getTabs().add(tab1); Tab tab2 = new Tab(); tab2.setText("Tab 2"); tabPane.getTabs().add(tab2); rootPane.setCenter(tabPane); rootPane.prefHeightProperty().bind(scene.heightProperty()); rootPane.prefWidthProperty().bind(scene.widthProperty()); primaryStage.setScene(scene); primaryStage.show(); Set<Node> nodes = tabPane.lookupAll(".tab-close-button"); for (final Node node : nodes) { node.setUserData(node.getOnMouseReleased()); node.setOnMouseReleased(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent arg0) { boolean removeTab = false;
ytw
source share