JavaFX 1:bind 和 var 访问修饰符
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我想通了:
虽然,我真的不需要在这里指定宽度和高度,因为我可以通过阶段变量访问它们。 当舞台宽度和高度发生变化时,场景宽度和高度也会更新。 我发现,当绑定到场景宽度和高度而不是绑定到 var 宽度和高度时,canvasWidth 会更新得更好(只有在调整大小完成后才会更新)
Ok, I figured it out:
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)
更准确地说,场景的宽度和高度被声明为“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.
您不应该将场景尺寸绑定到任何东西。 主要是因为当用户尝试调整包含窗口的大小时,场景尺寸不会更新。
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.