2

I was writing a game using JavaFX. When I compiled the code using jdk-9, everything worked fine but when I compiled it using jdk-8u102 and ran the program, there was some extra space(about 10 pixels) on the right and bottom of the application window. In both cases the Scene size was correct but in case of java 8, the Stage is bigger on the right and bottom(although inquiring about the width or height of the Stage, using Stage.getWidth() or Stage.getHeight() methods, returns the same values in both cases).

I tried updating to jdk-8u151 but that didn't solve the problem.

Note - When I compiled the program using jdk-8 but ran using jre-9, the problem wasn't there anymore. So I'm guessing, the problem can be with the run time environment of java 8 instead of the jdk itself.

I found that Stage.setResizable(false) is causing the problem in jre-8. Also, I'm using Windows and the problem doesn't seem to be with jre-8 on linux.

Here is a code snippet of the application:

public void start(Stage primaryStage) throws Exception {
    ImageView spaceBackground = new ImageView("space.jpg");
    spaceBackground.setFitHeight(600);
    spaceBackground.setFitWidth(900);

    Group group = new Group(spaceBackground);
    Scene scene = new Scene(group, 900, 600);  

    primaryStage.setResizable(false);    // this method is causing the problem
    /*
    rest of the code
    */
}

This is a screen capture of the application window, running under jre-9: enter image description here

And here is the one running under jre-8: notice the white spaces on the right and bottom

Can anyone tell me what the cause might be here?

Arijit Ghosh
  • 59
  • 1
  • 5
  • 3
    I cannot reproduce the problem. Are you shure you don't resize the scene somewhere? – mayamar Nov 25 '17 at 15:11
  • @mayamar No, I'm not resizing the scene anywhere. Besides I'm taking the same source code and compiling and running it under _jre-8_ and _jre-9_. Also, just running the code snippet I provided, wont reproduce the problem. – Arijit Ghosh Nov 25 '17 at 16:14
  • Questions seeking debugging help **must** include the shortest code necessary to reproduce the problem in the question itself. Please read how to create a [MCVE]. – tambre Nov 25 '17 at 16:34
  • Any chance the following question contains related hints? https://stackoverflow.com/questions/20732100/javafx-why-does-stage-setresizablefalse-cause-additional-margins – Hay Nov 25 '17 at 16:40
  • @mayamar I've updated the code snippet and it will now reproduce the problem I'm having. – Arijit Ghosh Nov 25 '17 at 16:40
  • Yes @Hay _Stage.sizeToScene()_ solves the problem. Thanks – Arijit Ghosh Nov 25 '17 at 16:49
  • I suspect `new Scene(group)` (without setting an explicit size) also would solve the problem. – VGR Nov 25 '17 at 17:05

0 Answers0