import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.Tab; import javafx.scene.control.TabPane; import javafx.scene.layout.BorderPane; import javafx.scene.paint.Color; import javafx.stage.Stage; public class TabBug extends Application { public static void main( String[] args ) { Application.launch( TabBug.class, args ); } private TabPane tabPane; private int nextTabNumber = 1; @Override public void start( Stage primaryStage ) { primaryStage.setTitle( "Tab Bug Demo" ); BorderPane root = new BorderPane(); Scene scene = new Scene( root, 800, 250, Color.LIGHTGREEN ); tabPane = new TabPane(); tabPane.setTabClosingPolicy( TabPane.TabClosingPolicy.ALL_TABS ); Button btn = new Button(); btn.setText( "Press to create tab" ); btn.setOnAction( new EventHandler() { public void handle( ActionEvent event ) { final Tab tab = new Tab( "Tab #" + nextTabNumber ); tab.setContent( new Label( "dummy text" ) ); nextTabNumber++; tabPane.getTabs().add( tab ); } } ); root.setTop( btn ); root.setCenter( tabPane ); primaryStage.setScene( scene ); primaryStage.setVisible( true ); } }