如何将 JavaFX 2.0 应用程序置于浏览器窗口的中心
我正在 JavaFx 2.0 中构建一个应用程序,并希望在部署该应用程序时将其显示在浏览器窗口的中心。我在谷歌和雅虎上寻找过这个主题,但一无所获。非常感谢任何帮助。
I am building a application in JavaFx 2.0 and would like to, when the application is deployed, to have it show up on the center of the window of a browser. I have looked for this topic in google and yahoo and found nothing. Any help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看 源代码 的 JavaFX Ensemble 示例。 Ensemble 应用程序配置为运行以填充浏览器窗口,无论窗口大小如何。完成的方式是通过在启动应用程序的 JavaScript 中进行配置以及通过应用程序嵌入的 div 的 css 样式进行配置。
以下是 html 相关部分的摘录。
如果您需要 100% 覆盖率以外的内容,您可以将 100% 标记设置为 75%,并调整 css 样式以在页面中居中并具有所需的边距。
当前的Java 打包工具(例如javafxpackager 实用程序)不允许指定百分比宽度。我已经在 javafx jira 中为此创建了一个功能请求 - 您可以创建那里有一个帐户来查看请求。如果您使用这些工具来生成部署 html,那么您可能会手动或通过后处理 ant 脚本修改部署 html,如 Ensemble 示例应用程序的 build.xml 中所示。
Look at the source code for the JavaFX Ensemble example. The Ensemble application is configured to run to fill a browser window, no matter the size of the window. The way it is done is by configuration in the JavaScript which launches the app as well as via css styling of the div the application is embedded in.
Here is an extract of the relevant parts of the html.
If you need something other than 100% coverage, you can the 100% tags to, say 75%, and adjust the css styling to get centering in the page with the margins you want.
The current Java packaging tools (e.g. the javafxpackager utility), do not allow specification of percentange widths. I've created a feature request for this in the javafx jira - you can create an account there to view the request. If you use those tools to generate your deployment html, then you might have to modify the deployment html by hand or by a post-processing ant script, as can be seen in the build.xml for the Ensemble sample application.
您可以在 FXML 中使用 HBox 和 VBox 面板的组合。 Hier 是我测试过的代码:
“panel1”将在浏览器区域中拉伸。所以 HBox 和 VBox 也会。因为它们的子级具有“center”属性,所以“panel2”将居中。
You can use combination of HBox and VBox panels in your FXML. Hier is my tested code:
The 'panel1' will stretch in the browser area. So the HBox and VBox will also. Because they have 'center' attributes for their childeren, the 'panel2' will be centered.
使用这个 FXML
可能会解决你的问题
Use this FXML
Might solve your problem
尝试使用 StackPane 作为容器。它将把它包含的所有节点居中。
托斯顿
Try to use a StackPane as container. It will center all nodes it includes.
Torsten