Reputation: 55
Alert is class in javafx 1.3 but in javafx 2.1, is not. So what is replacement of alert in javafx 2.1 ?
Upvotes: 3
Views: 5198
Reputation: 1398
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,
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
Upvotes: 0
Reputation: 159291
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.
Upvotes: 4
Reputation: 2704
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?
Upvotes: 2