JavaFX:嵌入式 JavaFX 小程序丢失宽度和高度?
我有一个 JavaFX 小程序,其舞台的初始高度和宽度定义如下:
var stage:Stage = Stage {
title: "Blah"
scene: Scene {
height: 768
width: 1024
fill: Color.WHITE
...
此外,我在场景中布局了一些元素,这些元素出于布局目的而绑定到高度和宽度。 作为桌面程序,一切正常。
但是,当我使用以下代码将其作为小程序嵌入到 HTML 页面中时,小程序的大小正确,但场景的宽度和高度属性设置为零,即使有足够的空间。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Lol</title>
</head>
<body>
<h1>Lol</h1>
<script src="http://dl.javafx.com/1.2/dtfx.js"></script>
<div style="border:1px solid black">
<script>
javafx(
{
archive: "Lol.jar",
draggable: true,
width: 1024,
height: 768,
code: "lol.Main",
name: "Lol"
}
);
</script>
</div>
</body>
</html>
例如,表达式 {stage.width.toString()}
的计算结果为 0.0
。 这是怎么回事? 如何在 FX 代码中获取小程序的实际高度和宽度?
I have a JavaFX applet with the stage's initial height and width defined as such:
var stage:Stage = Stage {
title: "Blah"
scene: Scene {
height: 768
width: 1024
fill: Color.WHITE
...
Additionally, I have elements laid out in the scene that are bound to the height and width for layout purposes. All works fine as a Desktop program.
However, when I embed it into an HTML page as an applet using the following code, the applet is sized right, but the width and height properties of my scene are set to ZERO even though there's plenty of space.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Lol</title>
</head>
<body>
<h1>Lol</h1>
<script src="http://dl.javafx.com/1.2/dtfx.js"></script>
<div style="border:1px solid black">
<script>
javafx(
{
archive: "Lol.jar",
draggable: true,
width: 1024,
height: 768,
code: "lol.Main",
name: "Lol"
}
);
</script>
</div>
</body>
</html>
For example, the expression {stage.width.toString()}
evaluates to 0.0
. What's going on? How can I, inside the FX code, get the actual height and width of the applet?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
叹息...
我很快就解决了这个问题...显然使用
stage.width
只能在桌面模式下工作,而stage.scene.width
可以工作对于小程序和桌面应用程序......至少就我而言。 将此留给未来的 JavaFX 开发人员,祝福他们的心。Sigh...
I fixed this quickly... apparently using
stage.width
only works in Desktop mode, whereasstage.scene.width
works for both applets and desktop apps... at least in my case. Leaving this here for future JavaFX developers, bless their hearts.