Information Dialog
ActionType type = DialogFactory.showInfo(owner, "Just a short information!", null, "My InfoDialog Title");
Dialog<ActionType> infoDialog = DialogFactory.createInfo(null, "Just a short information!", "Some detailed information why the dialog is shown. On error give some hints on how to do it right. When the description is set to null this text element will not appear.", "My InfoDialog Title");
infoDialog.initModality(Modality.NONE);
infoDialog.showAndWait();
ActionType type = infoDialog.getResult();
You can set a custom icon by specifying an image by CSS just like in the example below.
Dialog<ActionType> d = DialogFactory.createInfo(null, "Information dialog with a custom graphic!", null, "My InfoDialog");
d.getRootPane().applyCss();
Node imageView = d.getRootPane().lookup(".message-icon");
imageView.setStyle("-fx-image: url(\"/com/jyloo/syntheticafx/demo/resources/icon/display.png\");");
d.showAndWait();
However, the cleaner approach is to create a custom style and apply the style to your dialog by adding a custom style class.
Dialog<ActionType> d = DialogFactory.createInfo(null, "Information dialog with a custom graphic!", null, "My InfoDialog");
d.getRootPane().getStyleClass().add("my-dialog");
d.showAndWait();
This requires that your custom stylesheet is already provided either by calling dialog.getRootPane().getStylesheets().add("path/to/customStyle.css")
or e.g. on application startup
through the StyleManager by calling StyleManager.getInstance().addUserAgentStylesheet(getClass().getResource("/path/to/customStyle.css").toExternalForm())
.
.my-dialog .message-icon{
-fx-image: url("/com/jyloo/syntheticafx/demo/resources/icon/display.png");
}
Warning Dialog
button.setOnAction(e->DialogFactory.showWarning(getScene().getWindow(), "Well, maybe you did something wrong!", null, "My WarningDialog"));
Error Dialog
button.setOnAction(e->DialogFactory.showError(getScene().getWindow(), "It looks like something went wrong!", null, "My ErrorDialog"));
Confirmation Dialog
DialogFactory.showConfirm(null, "Please confirm now...", "Fuller description of the message, the cause/situation and maybe it's consequences.", "My ConfirmationDialog", DialogFactory.ConfirmDialogController.Type.YES_NO_CANCEL, DialogActionType.CANCEL);
-
Dialog<String> d = DialogFactory.createInput(null, "Input your avatar name", "The name will be displayed on public conversations.", "My InputDialog", null);
d.showAndWait();
System.out.println("Result: " + d.getResult());
Details Dialog
DetailsDialog<ActionType> d = DialogFactory.createDetails(null, "Some details are hidden...", "Additional description goes here.", "My DetailsDialog", null);
TextArea n = new TextArea("Details\nDetails\nDetails");
//n.setWrapText(true);
d.setDetailsContent(n);
d.showAndWait();
Login Dialog
Dialog<Pair<String,String>> d = DialogFactory.createLogin(null, "To logon fill in your data and press OK.", "My LoginDialog", "Tom", "toms_password");
d.showAndWait();
System.out.println("Result: " + d.getResult());