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
  • 20,216
  • 5
  • 52
  • 58
TeemoBiceps
  • 346
  • 1
  • 5
  • 19

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
  • 20,216
  • 5
  • 52
  • 58