-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use JFXAlerts? #633
Comments
Here, now they have a place—all the boilerplate is done. #634 But there's nothing "demonstrated" yet. Can anyone help out with that? |
Use JFXDialog instead of alerts. |
Just for clarification, @XlintXms this issue is a request for JFXAlert documentation. |
@jfoenixadmin, I saw that you added an example of how to use a You mentioned in #634 that "unlike java Alerts, It'll be important to make it clear in the documentation how users should go about getting a result after a If one tries to use a While
would give you back the right result when using a |
If I understand correctly, the reason for this is because I may have found a way to work around this. Say we don't use An example: JFXTextField usernameTextField = new JFXTextField();
addUserButton.setOnAction(event -> {
// Ensure that the user can't close the alert.
JFXAlert<String> alert = new JFXAlert<>((Stage) addUserButton.getScene().getWindow());
alert.initModality(Modality.APPLICATION_MODAL);
alert.setOverlayClose(false);
// Create the content of the JFXAlert with JFXDialogLayout
JFXDialogLayout layout = new JFXDialogLayout();
layout.setHeading(new Label("Enter Username"));
layout.setBody(new VBox(new Label("Please enter the username of the person you would like to add."),
usernameTextField));
// Buttons get added into the actions section of the layout.
JFXButton addButton = new JFXButton("ADD");
addButton.setDefaultButton(true);
addButton.setOnAction(addEvent -> {
// When the button is clicked, we set the result accordingly
alert.setResult(usernameTextField.getText());
alert.hideWithAnimation();
});
JFXButton cancelButton = new JFXButton("CANCEL");
cancelButton.setCancelButton(true);
cancelButton.setOnAction(closeEvent -> alert.hideWithAnimation());
layout.setActions(addButton, cancelButton);
alert.setContent(layout);
Optional<String> result = alert.showAndWait();
if (result.isPresent()){
System.out.println("Your choice: " + result.get());
}
}); The sticky part of it is what happens if the result is never set (like in the case of the cancel button): |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Recently I discovered a way to avoid the The default result converter returns a result of type alert.setResultConverter(buttonType -> {
// We don't want to use a result converter,
// if there is no result set explicitly, then return null.
return null;
}); then it will no longer try to return a With this strategy, if we reuse the dialog, it's important to reset the result after you use it. If you don't, the same result sticks around for next time you use the dialog. Optional<String> result = alert.showAndWait();
if (result.isPresent()){
System.out.println("Your choice: " + result.get());
alert.setResult(null); // reset the result for next time
} |
thanks.it works! |
Can anyone please send the image of alert or dialog... I want to see it's look and feel. |
There's no place for JFXAlerts in the demo, yet! Allow me to take the first step.
The text was updated successfully, but these errors were encountered: