Set window size

The size of a JavaFX application window can be set in two places.

It can be set in either the Stage or the Scene object using the width and height variables.

When set in the Stage the width and height variables represent the size of the entire window including the window borders and the title bar at the top of the window.

import javafx.stage.Stage;
import javafx.scene.Scene;
 
Stage {
    title: "My JavaFX App"
    width:  250
    height: 250
    scene: Scene {   }
}

When set in the Scene the width and height variables represent the size of of the viewable content area within the window.

import javafx.stage.Stage;
import javafx.scene.Scene;
 
Stage {
    title: "My JavaFX App"
    scene: Scene {
        width: 250
        height: 250
    }
}

If there is a conflict between the Stage and Scene values, the Stage values win.

Generally, it is preferable to set the size within the Scene. This is especially beneficial when working on mobile applications where the screen resolution is fixed.

To set whether the window can be resized by the user use the resizable variable in the Stage object.

On Sat, 05/23/2009 - 22:37 Evgeni Sergeev (not verified) said:

This is a beautiful web page. It takes seconds to read and it answers the question immediately. We should be making more pages like this.

----
Wood sculpture gallery (Nik Sergeev)

On Sat, 05/23/2009 - 23:15 Evgeni Sergeev (not verified) said:

I'd like to add that I once I tried that, there was an issue inverse-binding to the Scene's width. The error reported was that it has "script-only access". The exact error was:
... width has script only (default) bind access in javafx.scene.Scene ...

But I wanted various dimensions to depend on the size of the scene. So the solution was as follows.

public var full_width:Number;
public var full_height:Number;
 
class SizeBoundingScene extends Scene {
    public var w = bind width on replace {
            //println("Now w {w}");
            full_width = w;
        };
    public var h = bind height on replace {
            //println("Now h {h}");
            full_height = h;
        };
}

Now I can bind to full_width and full_height.

On Tue, 09/01/2009 - 06:38 Jérôme JADOULLE (not verified) said:

Hello! Thank you for your post.

Following on this subject, would you, by any chance, know how to set a minimum size to the stage / scene when the resizable property is set to true?
I have tried to implement functions in minWidth of panels contained in the scene by returning a fixed value (for example 800.0) but that has no effect whatsoever.

thank you for your reply!

Jer