下面列出了javafx.scene.control.Alert#AlertType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** Real window creator */
private static void getNotification(String title, String body, Alert.AlertType type){
Alert alertBox = new Alert(type);
alertBox.setTitle(title);
alertBox.setHeaderText(null);
alertBox.setContentText(body);
alertBox.getDialogPane().setMinWidth(Region.USE_PREF_SIZE);
alertBox.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alertBox.setResizable(true); // Java bug workaround for JDR11/OpenJFX. TODO: nothing. really.
alertBox.getDialogPane().getStylesheets().add(AppPreferences.getInstance().getTheme());
Stage dialogStage = (Stage) alertBox.getDialogPane().getScene().getWindow();
dialogStage.setAlwaysOnTop(true);
dialogStage.getIcons().addAll(
new Image("/res/warn_ico32x32.png"),
new Image("/res/warn_ico48x48.png"),
new Image("/res/warn_ico64x64.png"),
new Image("/res/warn_ico128x128.png")
);
alertBox.show();
dialogStage.toFront();
}
public static Alert createAlertWithOptOut(Alert.AlertType type, String dialogKey, String title, String headerText,
String message, String optOutMessage, /*Callback<Boolean, Void> optOutAction,*/
ButtonType... buttonTypes) {
Alert alert = new Alert(type);
// Need to force the alert to layout in order to grab the graphic,
// as we are replacing the dialog pane with a custom pane
alert.getDialogPane().applyCss();
Node graphic = alert.getDialogPane().getGraphic();
// Create a new dialog pane that has a checkbox instead of the hide/show details button
// Use the supplied callback for the action of the checkbox
alert.setDialogPane(new DialogPane() {
@Override
protected Node createDetailsButton() {
CheckBox optOut = new CheckBox();
optOut.setText(optOutMessage);
optOut.setOnAction(event -> {
if (optOut.isSelected()) {
ignoreDialogs.add(dialogKey);
}
});
return optOut;
}
});
alert.getDialogPane().getButtonTypes().addAll(buttonTypes);
alert.getDialogPane().setContentText(message);
// Fool the dialog into thinking there is some expandable content
// a Group won't take up any space if it has no children
alert.getDialogPane().setExpandableContent(new Group());
alert.getDialogPane().setExpanded(true);
// Reset the dialog graphic using the default style
alert.getDialogPane().setGraphic(graphic);
alert.setTitle(title);
alert.setHeaderText(headerText);
return alert;
}
public static void showAlert(Alert.AlertType alertType, Window owner, String title, String message) {
Alert alert = new Alert(alertType);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.initOwner(owner);
alert.show();
}
public static void showAlert(Alert.AlertType alertType, Window owner, String title, String message) {
Alert alert = new Alert(alertType);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.initOwner(owner);
alert.show();
}
public static void showAlert(Alert.AlertType alertType, Window owner, String title, String message) {
Alert alert = new Alert(alertType);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.initOwner(owner);
alert.show();
}
private void showDialog(String title, String header, String content, Alert.AlertType alertType) {
Alert alert = new Alert(alertType);
alert.setContentText(content);
alert.setTitle(title);
alert.setHeaderText(header);
alert.show();
}
public static void showException(Alert.AlertType alertType, String title, String text, Throwable ex) {
Platform.runLater(() -> {
Alert alert = new Alert(alertType);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(text);
if (SHOW_STACKTRACE && ex != null) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
String exceptionText = sw.toString();
Label label = new Label("Exception stacktrace:");
TextArea textArea = new TextArea(exceptionText);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(textArea, Priority.ALWAYS);
GridPane.setHgrow(textArea, Priority.ALWAYS);
GridPane expContent = new GridPane();
expContent.setMaxWidth(Double.MAX_VALUE);
expContent.add(label, 0, 0);
expContent.add(textArea, 0, 1);
alert.getDialogPane().setExpandableContent(expContent);
}
alert.showAndWait();
});
}
private Alert.AlertType getAlertType(MessageType type) {
switch (type) {
case Error:
return Alert.AlertType.ERROR;
case Info:
return Alert.AlertType.INFORMATION;
}
return Alert.AlertType.NONE;
}
public static void showAlert(String title, String Content, Alert.AlertType alertType) {
Alert alert = new Alert(alertType);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(Content);
alert.showAndWait();
}
/**
* Display an alert to the user with the specified information.
* @param title alert title
* @param description alert content description
* @param type alert type
*/
private void showMessage(String title, String description, Alert.AlertType type) {
Alert alert = new Alert(type);
alert.setTitle(title);
alert.setContentText(description);
alert.show();
}
private static void showMessageDialog(Alert.AlertType type, String title, String message, Stage owner) {
FutureTask<Void> dialog = new FutureTask<>(() -> {
final Alert alert = new Alert(type);
alert.setTitle(title);
alert.setContentText(message);
alert.initOwner(owner);
alert.showAndWait();
return null;
});
Platform.runLater(dialog);
}
public TrexAlertBuilder setType(Alert.AlertType type) {
alert.setAlertType(type);
return this;
}
DetailedAlert(Alert.AlertType alertType) {
super(alertType);
}
DetailedAlert(Alert.AlertType alertType, String contentText, ButtonType... buttons) {
super(alertType, contentText, buttons);
}
/**
*
* delegates to {@link #alert(Alert.AlertType, boolean)} with {@code isResizable = true}.
*
* @param type type of alert
* @return {@link Alert} with the title set to {@link Paintera.Constants#NAME}
*/
public static Alert alert(final Alert.AlertType type) {
return alert(type, true);
}