java JavaFX 中类似 JOptionPane 的对话框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27866344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 12:33:20  来源:igfitidea点击:

Dialog Box like JOptionPane in JavaFX

javajavafxdialogmodal-dialog

提问by Biswadip Dey

I found this article JavaFX 2 Dialogsand I am using it. But this dialog accepts only Stage Object. Is there any option to display dialog box which will accept AnchorPane as its parent. That Is similar to JoptionPane where we can pass any object which are derived from Component for example JPanel, JTitlePane, etc. And the dialog box I am using it is bieng display on task bar of windows also (passing null as parent). I want show a message like this

我找到了这篇文章JavaFX 2 Dialogs并且我正在使用它。但是这个对话框只接受舞台对象。是否有任何选项可以显示接受 AnchorPane 作为其父级的对话框。这与 JoptionPane 类似,我们可以传递从 Component 派生的任何对象,例如 JPanel、JTitlePane 等。我使用它的对话框也在窗口的任务栏上显示(将 null 作为父项传递)。我想显示这样的消息

enter image description here

在此处输入图片说明

Is it possible to display an AnchorPane to the top of the other AnchorPane or TableView like the attached picture which will be modal as well?

是否可以像附加的图片一样将 AnchorPane 显示到另一个 AnchorPane 或 TableView 的顶部,这也是模态的?

回答by Mateus Viccari

JavaFX does not have a pre-defined dialog api like swing's JOptionPane.

JavaFX 没有像 Swing 的 JOptionPane 那样的预定义对话框 API。

Take a look at ControlsFX: http://fxexperience.com/controlsfx/

看看 ControlsFX:http: //fxexperience.com/controlsfx/

They have a set of Dialogs fit for most situations: http://fxexperience.com/controlsfx/features/dialogs/

他们有一组适合大多数情况的对话框:http: //fxexperience.com/controlsfx/features/dialogs/

You can call a dialog using:

您可以使用以下方法调用对话框:

Dialogs.create().message("Hi!").showInformation();

Otherwise, if you don't want to use third party libraries, you will have to create your own set of dialogs.

否则,如果您不想使用第三方库,则必须创建自己的一组对话框。

------- UPDATE -------

- - - - 更新 - - - -

There is now a built in API for dialogs in JavaFX since jre8u60 (Alert, ChoiceDialog, TextInputDialog, etc.), check it out: controlsfx Dialogs deprecated for what?

现在有一个因为jre8u60内置的API为对话框中的JavaFX( ,,等),检查出来: controlsfx对话框过时的什么?AlertChoiceDialogTextInputDialog