220 }
221
222 /**
223 * Creates an alert with the given contentText, ButtonTypes, and AlertType
224 * (refer to the {@link AlertType} documentation for clarification over which
225 * one is most appropriate).
226 *
227 * <p>By passing in a variable number of ButtonType arguments, the developer
228 * is directly overriding the default buttons that will be displayed in the
229 * dialog, replacing the pre-defined buttons with whatever is specified in the
230 * varargs array.
231 *
232 * <p>By passing in an AlertType, default values for the
233 * {@link #titleProperty() title}, {@link #headerTextProperty() headerText},
234 * and {@link #graphicProperty() graphic} properties are set. Once the Alert
235 * is instantiated, developers are able to modify the values of the alert as
236 * desired.
237 */
238 public Alert(@NamedArg("alertType") AlertType alertType,
239 @NamedArg("contentText") String contentText,
240 ButtonType... buttons) {
241 super();
242
243 final DialogPane dialogPane = getDialogPane();
244 dialogPane.setContentText(contentText);
245 getDialogPane().getStyleClass().add("alert");
246
247 dialogPaneRef = new WeakReference<>(dialogPane);
248
249 hasCustomButtons = buttons != null && buttons.length > 0;
250 if (hasCustomButtons) {
251 for (ButtonType btnType : buttons) {
252 dialogPane.getButtonTypes().addAll(btnType);
253 }
254 }
255
256 setAlertType(alertType);
257
258 // listening to property changes on Dialog and DialogPane
259 dialogPaneProperty().addListener(o -> updateListeners());
260 titleProperty().addListener(titleListener);
|
220 }
221
222 /**
223 * Creates an alert with the given contentText, ButtonTypes, and AlertType
224 * (refer to the {@link AlertType} documentation for clarification over which
225 * one is most appropriate).
226 *
227 * <p>By passing in a variable number of ButtonType arguments, the developer
228 * is directly overriding the default buttons that will be displayed in the
229 * dialog, replacing the pre-defined buttons with whatever is specified in the
230 * varargs array.
231 *
232 * <p>By passing in an AlertType, default values for the
233 * {@link #titleProperty() title}, {@link #headerTextProperty() headerText},
234 * and {@link #graphicProperty() graphic} properties are set. Once the Alert
235 * is instantiated, developers are able to modify the values of the alert as
236 * desired.
237 */
238 public Alert(@NamedArg("alertType") AlertType alertType,
239 @NamedArg("contentText") String contentText,
240 @NamedArg("buttonTypes") ButtonType... buttons) {
241 super();
242
243 final DialogPane dialogPane = getDialogPane();
244 dialogPane.setContentText(contentText);
245 getDialogPane().getStyleClass().add("alert");
246
247 dialogPaneRef = new WeakReference<>(dialogPane);
248
249 hasCustomButtons = buttons != null && buttons.length > 0;
250 if (hasCustomButtons) {
251 for (ButtonType btnType : buttons) {
252 dialogPane.getButtonTypes().addAll(btnType);
253 }
254 }
255
256 setAlertType(alertType);
257
258 // listening to property changes on Dialog and DialogPane
259 dialogPaneProperty().addListener(o -> updateListeners());
260 titleProperty().addListener(titleListener);
|