JavaFX:嵌入式 JavaFX 小程序丢失宽度和高度?

发布于 2024-08-01 18:53:40 字数 1061 浏览 1 评论 0原文

我有一个 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 技术交流群。

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

发布评论

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

评论(1

囍笑 2024-08-08 18:53:40

叹息...

我很快就解决了这个问题...显然使用stage.width只能在桌面模式下工作,而stage.scene.width可以工作对于小程序和桌面应用程序......至少就我而言。 将此留给未来的 JavaFX 开发人员,祝福他们的心。

Sigh...

I fixed this quickly... apparently using stage.width only works in Desktop mode, whereas stage.scene.width works for both applets and desktop apps... at least in my case. Leaving this here for future JavaFX developers, bless their hearts.

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