To reproduce close the tab.
import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class TabPaneVetoTest extends Application {
TabPane testedControl;
@Override
public void start(Stage stage) {
initTestedControl();
HBox root = new HBox(20d);
root.getChildren().add(testedControl);
Scene scene = new Scene(root, 300, 250);
stage.setScene(scene);
stage.setTitle(System.getProperty("java.runtime.version") + "; " + System.getProperty("javafx.runtime.version"));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
private void initTestedControl() {
testedControl = new TabPane();
Tab tab = new Tab("Vetoing tab");
tab.setClosable(true);
Label lbl = new Label("Content");
lbl.addEventHandler(Tab.TAB_CLOSE_REQUEST_EVENT, new EventHandler<Event>() {
@Override
public void handle(Event t) {
System.out.println("t = " + t);
t.consume();
}
});
tab.setContent(lbl);
testedControl.getTabs().add(tab);
testedControl.setMinSize(200.0, 100.0);
}
}
import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class TabPaneVetoTest extends Application {
TabPane testedControl;
@Override
public void start(Stage stage) {
initTestedControl();
HBox root = new HBox(20d);
root.getChildren().add(testedControl);
Scene scene = new Scene(root, 300, 250);
stage.setScene(scene);
stage.setTitle(System.getProperty("java.runtime.version") + "; " + System.getProperty("javafx.runtime.version"));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
private void initTestedControl() {
testedControl = new TabPane();
Tab tab = new Tab("Vetoing tab");
tab.setClosable(true);
Label lbl = new Label("Content");
lbl.addEventHandler(Tab.TAB_CLOSE_REQUEST_EVENT, new EventHandler<Event>() {
@Override
public void handle(Event t) {
System.out.println("t = " + t);
t.consume();
}
});
tab.setContent(lbl);
testedControl.getTabs().add(tab);
testedControl.setMinSize(200.0, 100.0);
}
}