Pikamander2
Pikamander2

Reputation: 8299

Why is my JavaFX window not the right width?

When I make a JavaFX window:

    Scene scene = new Scene(pane, 600, 800);
    primaryStage.setResizable(false);
    primaryStage.setScene(scene);
    primaryStage.show();

The resulting window is about 610 pixels wide.

 

If I use setWidth:

    Scene scene = new Scene(pane, 600, 800);
    primaryStage.setResizable(false);
    primaryStage.setWidth(600);
    primaryStage.setScene(scene);
    primaryStage.show();

The window ends up being about 594 pixels wide.

 

Why does this happen, and how can I get my window to be the correct size?

Upvotes: 0

Views: 1085

Answers (1)

Pikamander2
Pikamander2

Reputation: 8299

Apparently it's a long standing bug that happens when setResizable is used.

I fixed it by using the sizeToScene function.

    Scene scene = new Scene(pane, 600, 800);
    primaryStage.setResizable(false);
    primaryStage.sizeToScene();
    primaryStage.setScene(scene);
    primaryStage.show();

Upvotes: 1

Related Questions