简体   繁体   English

如何创建JavaFX对话框?

[英]How to create a JavaFX dialog?

I need to create a dialog in JavaFX. 我需要在JavaFX中创建一个对话框。 I know that I can make the Stage behave like a dialog by modifying modal, owner and resizable properties. 我知道我可以通过修改模态,所有者和可调整大小的属性使舞台表现得像一个对话框。

But how do I hide the "minimize" and "maximize" buttons from the Stage window? 但是如何从舞台窗口隐藏“最小化”和“最大化”按钮? Typical dialogs only have the "close" button. 典型对话框只有“关闭”按钮。

Under Windows 7, initializing to StageStyle.UTILITY before you show the window will create a window with only a close button and no minimize or maximize button: 在Windows 7下,在显示窗口之前初始化为StageStyle.UTILITY将创建一个仅包含关闭按钮且没有最小化或最大化按钮的窗口:

Stage dialog = new Stage();
dialog.initStyle(StageStyle.UTILITY);
Scene scene = new Scene(new Group(new Text(25, 25, "Hello World!")));
dialog.setScene(scene);
dialog.show();

If you would like a complete set of basic JavaFX dialogs I would recommend the JavaFX UI sandbox dialogs . 如果您想要一套完整的基本JavaFX对话框,我建议使用JavaFX UI沙箱对话框

The JavaFX UI Sandbox was not created by me and is not hosted on my site (source is hosted by Oracle). JavaFX UI Sandbox不是由我创建的,并且不在我的站点上托管(源由Oracle托管)。 I requested Oracle to document the sandbox dialog API . 请求Oracle记录沙箱对话框API If you like, you may vote for or comment on the request. 如果您愿意,您可以投票或评论该请求。

Makery's blog has some minimal 3rd party documentation of the sandbox dialogs, including basic usage examples as well as a backport of the dialog portion to JavaFX 2.2. Makery的博客提供了沙盒对话框的一些最小的第三方文档,包括基本用法示例以及JavaFX 2.2对话框部分的后端口。

Update 更新

The JavaFX UI Sandbox has been superseded by the ControlsFX project . JavaFX UI Sandbox已被ControlsFX项目取代。

Update 更新

Java 8u40 will include JavaFX dialogs built into the core platform APIs. Java 8u40将包含内置于核心平台API中的JavaFX对话框 You can try an early access release of Java8u40 . 您可以尝试Java8u40早期访问版本 The relevant class is javafx.scene.control.Dialog and it's related subclasses such as javafx.scene.control.Alert (the Alert class is for showing standard dialogs which are similar to Swing's JOptionPane class - so you don't need to use JOptionPane to get out of the box standard dialog functionality). 相关的类是javafx.scene.control.Dialog和它的相关子类,如javafx.scene.control.Alert(Alert类用于显示类似于Swing的JOptionPane类的标准对话框 - 因此您不需要使用JOptionPane开箱即用标准对话框功能)。

Makery wrote a new blog tutorial for dialog functionality provided in Java 8u40 . Makery为Java 8u40中提供了一个关于对话功能的新博客教程

Related Questions 相关问题

You can also try my approach to the custom dialog window for Java FX 8. Both: source code with practical use example, and runnable demo are available in the link below: 您还可以尝试我的方法来访问Java FX 8的自定义对话框窗口。两个:具有实际使用示例的源代码和可运行的演示可在以下链接中找到:

https://github.com/bluevoxel/ChooseStage https://github.com/bluevoxel/ChooseStage

And that how it's looks like: 它看起来如何:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM