0

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?

Pikamander2
  • 7,332
  • 3
  • 48
  • 69

1 Answers1

1

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();
Community
  • 1
  • 1
Pikamander2
  • 7,332
  • 3
  • 48
  • 69
  • Well, there is this bug, but also you assume, that scene width = stage width, which isn't necessarily true, since the stage size includes decorations... – fabian Oct 18 '16 at 08:17