package bug; import javafx.application.Application; import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ButtonBuilder; import javafx.scene.input.MouseEvent; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class Bug extends Application{ /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here launch(Bug.class,args); } @Override public void start(final Stage stage) throws Exception { HBox buttonsPane = new HBox(); Button centerButton = ButtonBuilder.create() .text("Center") .alignment(Pos.CENTER) .prefWidth(180) .onMouseClicked(new EventHandler() { @Override public void handle(MouseEvent arg0) { stage.centerOnScreen(); } }) .build(); buttonsPane.getChildren().add(centerButton); Scene scene = new Scene(buttonsPane,300,300); stage.setScene(scene); stage.show(); } }