JavaFX 1:bind 和 var 访问修饰符

发布于 2024-07-21 07:03:02 字数 414 浏览 11 评论 0原文

 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
    }
}

为什么宽度有效,但高度无效? 而且,我能做些什么来解决这个问题? Netbeans 说:

height 在 javafx.scene.Scene 中仅具有脚本(默认)绑定访问权限

 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

温馨耳语 2024-07-28 07:03:02

好吧,我想通了:

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
               }
    }
}

虽然,我真的不需要在这里指定宽度和高度,因为我可以通过阶段变量访问它们。 当舞台宽度和高度发生变化时,场景宽度和高度也会更新。 我发现,当绑定到场景宽度和高度而不是绑定到 var 宽度和高度时,canvasWidth 会更新得更好(只有在调整大小完成后才会更新)

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)

Smile简单爱 2024-07-28 07:03:02

更准确地说,场景的宽度和高度被声明为“public-init”。 这意味着它们只能在初始化时设置。 场景对象文字中高度的绑定意味着高度将被更新,因此会出现错误。 舞台的宽度和高度被声明为“公共”,这意味着它们可以更新。

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.

情归归情 2024-07-28 07:03:02

您不应该将场景尺寸绑定到任何东西。 主要是因为当用户尝试调整包含窗口的大小时,场景尺寸不会更新。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文