What is replacement of alert in javafx 2.1 ? Alert is in javafx 1.3 but not in javafx 2.1

南楼画角 提交于 2019-12-22 10:23:26

问题


Alert is class in javafx 1.3 but in javafx 2.1, is not. So what is replacement of alert in javafx 2.1 ?


回答1:


Teocali is correct. Alert dialogs go into the platform in 3.0, which is currently under development.

JavaFX 2.2 features support for dialogs which suspend execution when they are displayed. This makes creating your own alert implementation (by calling stage.showAndWait()) pretty trivial.

(to access the JavaFX jira links in this answer, you can sign up for a jira account upon clicking on one of the links).

Jonathan Giles (a JavaFX developer) notes:

The Dialogs class (as it is currently called) did not make it into JavaFX 2.2, due to lack of time. I have just now pushed my proof of concept Dialogs class into the JavaFX Lombard (aka 3.0) repo, so it may possibly be included in that release. Whilst a long way off, at least with public builds to start soon, you can develop your applications using the JavaFX 3.0 builds and make use of the API (and provide feedback on how to improve it).

I created a Modal Confirm dialog sample.

Anton created a JavaFXDialog project.




回答2:


For what it's worth, I don't think there is any support for modal dialog in JavaFx 2.0 for the moment, and so for Alert style dialog box. Maybe you will find more information here : How to create and show common dialog (Error, Warning, Confirmation) in JavaFX 2.0?




回答3:


I found this thread to be one of the few providing an example of a javafx dialogs for use with WebView. I've created the following utility which helps in the creation of dialogs. Download the following files,

  • JavaScriptDialog.java
  • JavaScriptDialog.css

and use with a WebView as follows:

webEngine.setPromptHandler(new Callback<PromptData, String>() {
  @Override
  public String call(PromptData arg0) {
    JavaScriptDialog dialog = new JavaScriptDialog(stage, arg0.getMessage());
    dialog.addPrompt(arg0.getDefaultValue());
    dialog.addAcceptButton();
    dialog.addRejectButton();
    dialog.showAndWait();
    return dialog.getPrompt();
  }
});

Similar can be done for alert and confirm. This code is a stopgap until WebView dialogs are a part of JavaFX. It could probably be improved and there might be better alternatives, but this works for me. Please feel free to use and adapt and contact me with patches if you wish to share your enhancements.

It was adapted from the example provided by jewelsea



来源:https://stackoverflow.com/questions/11794987/what-is-replacement-of-alert-in-javafx-2-1-alert-is-in-javafx-1-3-but-not-in-j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!