views:

602

answers:

3
 var width = 400;
 var height = 400;

Stage {
    style: StageStyle.TRANSPARENT

    onClose: function():Void {
       System.exit(0);
    }

    scene: Scene {
        content: Scribble {}
        width: width
        height: bind height
    }
}

Why does the width work, but the height not? And, what can I do to fix this? Netbeans is saying:

height has script only(default) bind access in javafx.scene.Scene

A: 

You should not bind the scene dimensions to anything. Mostly because the scene dimensions will not get updated when the user tries to resize the containing window.

Honza
But that's what I want to happen - I want to be able to bind the size of the window
Louis Sayers
I suppose I should save the scene as a variable and update the width/height automatically?
Louis Sayers
I mean manually *
Louis Sayers
+2  A: 

Ok, I figured it out:

var width : Number = 400;
var height : Number = 400;

var stage:Stage = Stage {
    width: bind width with inverse
    height: bind width with inverse
    scene: Scene {
      content: Scribble {
                 canvasWidth: bind stage.scene.width
                 canvasHeight: bind stage.scene.height
               }
    }
}

Although, I don't really need to specify the width and height here, because I can access these through the stage variable. The scene width and height updates when the stage width and height changes. I've found that the canvasWidth will update a lot better when bound to the scene width and height rather than to the var width and height (which only update once the resize is complete)

Louis Sayers
+1  A: 

To be more precise on this, the Scene's width and height are declared as "public-init". This means they can only be set at initialization time. The bind on height in the Scene Object literal implies that height will be updated, hence the error. The Stage's width and height are declared as "public" meaning they can be updated.

JimClarke