2

Im new to JavaFX and have to program a software for my school project.

If my program is running i can scale the window as usual. The whole content in the window stays at the position which i gave them. Now i would like to center the whole content of the program while I'm scaling the open window.

It should work like the margin:auto in CSS where the container or pane is always in the middle of the window, doesn't matter what size the window has.

I am using FXML.

DVarga
  • 21,311
  • 6
  • 55
  • 60
TeemoBiceps
  • 386
  • 1
  • 6
  • 22

1 Answers1

1

You can have a VBox as the root container of your Scene, and set the aligment of the VBox to CENTER.

VBox vBox = new VBox();
vBox.setAlignment(Pos.CENTER);
Scene scene = new Scene(vBox,400,400);

For more detailed description, please read this question: How do I center JavaFX controls

Community
  • 1
  • 1
DVarga
  • 21,311
  • 6
  • 55
  • 60