如何创建 JavaFX 对话框? [英] How to create a JavaFX dialog?

查看:39
本文介绍了如何创建 JavaFX 对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 JavaFX 中创建一个对话框.我知道我可以通过修改模式、所有者和可调整大小的属性使舞台表现得像一个对话框.

I need to create a dialog in 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.

推荐答案

在 Windows 7 下,初始化为 StageStyle.UTILITY 在显示窗口之前将创建一个只有关闭按钮而没有最小化或最大化按钮的窗口:

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:

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();

如果您想要一套完整的基本 JavaFX 对话框,我会推荐 JavaFX UI 沙箱对话框.

If you would like a complete set of basic JavaFX dialogs I would recommend the JavaFX UI sandbox dialogs.

JavaFX UI 沙盒不是我创建的,也不是托管在我的网站上(源代码由 Oracle 托管).我请求 Oracle 记录沙箱对话框 API.如果您愿意,您可以投票支持或评论该请求.

The JavaFX UI Sandbox was not created by me and is not hosted on my site (source is hosted by Oracle). I requested Oracle to document the sandbox dialog API. If you like, you may vote for or comment on the request.

Makery 的博客 有一些沙盒对话框的最小 3rd 方文档,包括基本使用示例以及将对话框部分向后移植到 JavaFX 2.2.

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.

更新

JavaFX UI 沙盒已被 ControlsFX 项目取代.

The JavaFX UI Sandbox has been superseded by the ControlsFX project.

更新

Java 8u40 将在核心中包含 JavaFX 对话框平台 API.您可以尝试Java8u40 的早期访问版本.相关类是 javafx.scene.control.Dialog 及其相关子类,例如 javafx.scene.control.Alert(Alert 类用于显示类似于 Swing 的 JOptionPane 类的标准对话框 - 因此您不需要使用 JOptionPane开箱即用的标准对话框功能).

Java 8u40 will include JavaFX dialogs built into the core platform APIs. You can try an early access release of 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).

Makery 为 Java 8u40 中提供的对话框功能编写了一个新的博客教程.

相关问题

这篇关于如何创建 JavaFX 对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆