I'm experiencing a very odd behaviour, which I suspect to be a bug in the JavaFX 9 API, but I'm cautious as it's more likely that I'm missing something.
MCVE:
public class MainApp extends Application {
private Stage primaryStage;
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
double xCord = 200;
double yCord = 200;
double width = 400;
double height = 400;
BorderPane borderPane = new BorderPane(new Button("Button"));
Scene scene = new Scene(borderPane);
primaryStage.setX(xCord);
primaryStage.setY(yCord);
primaryStage.setWidth(width);
primaryStage.setHeight(height);
primaryStage.setScene(scene);
primaryStage.show();
System.out.println(primaryStage.getWidth());
System.out.println(primaryStage.getHeight());
primaryStage.setOnCloseRequest(e -> {
System.out.println(primaryStage.getWidth());
System.out.println(primaryStage.getHeight());
});
}
}
I tested this on Linux (GNOME and and FVWM) + Windows. The issue was on Linux only, namely that the width/height values changed in the close operation. Example output:
400.0
400.0
404.0
433.0
My guess is that the window decoration is part of the values but only in the second block. During the app running it is not included and the originally set values are reported. On GNOME I got a slightly different change (w: 0, h: 37) as the decoration is also different.
I tested it on Java 8 and there was no difference at all. Windows also seemed to work as expected, the same output in both sections. I searched the JDK Bugs but didn't find it this reported. I was hoping someone could confirm if this is expected behaviour, or indeed a regression.
The problem that it causes me is that I can't implement a robust preferences save for window size/position, as on Linux the windows crawls away. (Scene width/height can be used as a workaround, but it's still suspicious.)