Java Code Examples for javafx.scene.control.Alert#show()

The following examples show how to use javafx.scene.control.Alert#show() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceWindow.java    From ns-usbloader with GNU General Public License v3.0 6 votes vote down vote up
/** 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();
}
 
Example 2
Source File: ContextMenuCreateSaveset.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * When ROOT node is completely empty, create a new folder with the current timestamp.
 */
private void checkRootNode() {
    Node rootNode = saveAndRestoreService.getRootNode();

    if (saveAndRestoreService.getChildNodes(rootNode).isEmpty()) {
        Node newFolderBuild = Node.builder()
                .nodeType(NodeType.FOLDER)
                .name(savesetTimeFormat.format(Instant.now()) + " (Auto-created)")
                .build();

        try {
            saveAndRestoreService.createNode(rootNode.getUniqueId(), newFolderBuild);
        } catch (Exception e) {
            String alertMessage = "Cannot create a new folder under root node: " + rootNode.getName() + "(" + rootNode.getUniqueId() + ")";
            Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setContentText(alertMessage);
            alert.show();

            LOGGER.severe(alertMessage);

            e.printStackTrace();
        }
    }
}
 
Example 3
Source File: GoogleCloudCredentialsAlert.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public void show()
{
	final Hyperlink hyperlink = new Hyperlink("Google Cloud SDK");
	hyperlink.setOnAction(e -> Paintera.getApplication().getHostServices().showDocument(googleCloudSdkLink));

	final TextArea area = new TextArea(googleCloudAuthCmd);
	area.setFont(Font.font("monospace"));
	area.setEditable(false);
	area.setMaxHeight(24);

	final TextFlow textFlow = new TextFlow(
			new Text("Please install "),
			hyperlink,
			new Text(" and then run this command to initialize the credentials:"),
			new Text(System.lineSeparator() + System.lineSeparator()),
			area);

	final Alert alert = PainteraAlerts.alert(Alert.AlertType.INFORMATION);
	alert.setHeaderText("Could not find Google Cloud credentials.");
	alert.getDialogPane().contentProperty().set(textFlow);
	alert.show();
}
 
Example 4
Source File: ResourceView.java    From sis with Apache License 2.0 6 votes vote down vote up
private void addFeaturePanel(String filePath) {
    try {
        DataStore ds = DataStores.open(filePath);
        setContent(new FeatureTable(ds, 18));
        root.getChildren().addAll(temp);
        temp.clear();
    } catch (DataStoreException e) {
        final Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle("An error has occurred");
        Label lab = new Label(e.getMessage());
        lab.setWrapText(true);
        lab.setMaxWidth(650);
        VBox vb = new VBox();
        vb.getChildren().add(lab);
        alert.getDialogPane().setContent(vb);
        alert.show();
    }
}
 
Example 5
Source File: App.java    From DeskChan with GNU Lesser General Public License v3.0 5 votes vote down vote up
static void showThrowable(String sender, String className, String message, List<StackTraceElement> stacktrace) {
	if (!Main.getProperties().getBoolean("error-alerting", true)) return;

	Alert alert = new Alert(Alert.AlertType.ERROR);
	((Stage) alert.getDialogPane().getScene().getWindow()).getIcons().add(new Image(App.ICON_URL.toString()));

	alert.setTitle(Main.getString("error"));
	alert.initModality(Modality.WINDOW_MODAL);
	alert.setHeaderText(className + " " + Main.getString("caused-by") + " " + sender);
	alert.setContentText(message);
	StringBuilder exceptionText = new StringBuilder ();
	for (Object item : stacktrace)
		exceptionText.append((item != null ? item.toString() : "null") + "\n");

	TextArea textArea = new TextArea(exceptionText.toString());
	textArea.setEditable(false);
	textArea.setWrapText(true);
	textArea.setMaxWidth(Double.MAX_VALUE);
	textArea.setMaxHeight(Double.MAX_VALUE);

	CheckBox checkBox = new CheckBox(Main.getString("enable-error-alert"));
	checkBox.setSelected(Main.getProperties().getBoolean("error-alerting", true));
	checkBox.selectedProperty().addListener((obs, oldValue, newValue) -> {
		Main.getProperties().put("error-alerting", newValue);
	});

	BorderPane pane = new BorderPane();
	pane.setTop(checkBox);
	pane.setCenter(textArea);

	alert.getDialogPane().setExpandableContent(pane);
	alert.show();
}
 
Example 6
Source File: QualityControlViewPane.java    From constellation with Apache License 2.0 5 votes vote down vote up
/**
 * Display a dialog containing all Rule objects registered with the Quality
 * Control View and which matched for a given identifier.
 *
 * @param owner The owner Node
 * @param identifier The identifier of the graph node being displayed.
 * @param rules The list of rules measured against this graph node.
 */
private static void showRuleDialog(final Node owner, final String identifier, final List<Pair<Integer, String>> rules) {
    final ScrollPane sp = new ScrollPane();
    sp.setPrefHeight(512);
    sp.setPrefWidth(512);
    sp.setFitToWidth(true);
    sp.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
    sp.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);

    final VBox vbox = new VBox();
    vbox.prefWidthProperty().bind(sp.widthProperty());
    vbox.setPadding(Insets.EMPTY);
    for (final Pair<Integer, String> rule : rules) {
        final String[] t = rule.getValue().split("§");

        final String quality = rule.getKey() == 0 ? Bundle.MSG_NotApplicable() : "" + rule.getKey();
        final String title = String.format("%s - %s", quality, t[0]);

        final Text content = new Text(t[1]);
        content.wrappingWidthProperty().bind(sp.widthProperty().subtract(16)); // Subtract a random number to avoid the vertical scrollbar.

        final TitledPane tp = new TitledPane(title, content);
        tp.prefWidthProperty().bind(vbox.widthProperty());
        tp.setExpanded(false);
        tp.setWrapText(true);

        vbox.getChildren().add(tp);
    }
    sp.setContent(vbox);

    final Alert alert = new Alert(Alert.AlertType.INFORMATION);
    alert.setHeaderText(String.format(Bundle.MSG_QualtyControlRules(), identifier));
    alert.getDialogPane().setContent(sp);
    alert.setResizable(true);
    alert.show();
}
 
Example 7
Source File: AlertHelper.java    From javase with MIT License 5 votes vote down vote up
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();
}
 
Example 8
Source File: AlertHelper.java    From javase with MIT License 5 votes vote down vote up
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();
}
 
Example 9
Source File: LoadDialog.java    From Animu-Downloaderu with MIT License 5 votes vote down vote up
public static void showDialog(Window owner, String title, Message message) {
	alert = new Alert(AlertType.NONE);
	alert.initOwner(owner);
	alert.setTitle(title);
	ObservableMap<String, String> messages = message.getMessages();
	StringBuilder msg = new StringBuilder();
	messages.forEach((key, value) -> msg.append(String.format("%s\t: %s%n", key, value)));
	alert.getDialogPane().setMinHeight(messages.size() * 30d);
	alert.setContentText(msg.toString());

	// Run with small delay on each change
	messages.addListener((Change<? extends String, ? extends String> change) -> Platform.runLater(() -> {
		StringBuilder msgChange = new StringBuilder();
		messages.forEach((key, value) -> msgChange.append(String.format("%s\t: %s%n", key, value)));
		alert.setContentText(msgChange.toString());
		if (messages.values().stream().allMatch(val -> val.startsWith(Message.processed))) {
			stopDialog();
			message.clearMessages();
		}
	}));

	alert.initModality(Modality.APPLICATION_MODAL);
	alert.getDialogPane().getStylesheets()
			.add(LoadDialog.class.getResource("/css/application.css").toExternalForm());
	// Calculate the center position of the parent Stage
	double centerXPosition = owner.getX() + owner.getWidth() / 2d;
	double centerYPosition = owner.getY() + owner.getHeight() / 2d;

	alert.setOnShowing(e -> {
		alert.setX(centerXPosition - alert.getDialogPane().getWidth() / 2d);
		alert.setY(centerYPosition - alert.getDialogPane().getHeight() / 2d);
	});
	alert.show();
}
 
Example 10
Source File: FileSystem.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private void updateFromDirectoryChooser(final File initialDirectory, final Window ownerWindow) {

		final DirectoryChooser directoryChooser = new DirectoryChooser();
		directoryChooser.setInitialDirectory(initialDirectory);
		final File updatedRoot = directoryChooser.showDialog(ownerWindow);

		LOG.debug("Updating root to {} (was {})", updatedRoot, container.get());

		try {
			if (updatedRoot != null && !isN5Container(updatedRoot.getAbsolutePath())) {
				final Alert alert = PainteraAlerts.alert(Alert.AlertType.INFORMATION);
				alert.setHeaderText("Selected directory is not a valid N5 container.");
				final TextArea ta = new TextArea("The selected directory \n\n" + updatedRoot.getAbsolutePath() + "\n\n" +
						"A valid N5 container is a directory that contains a file attributes.json with a key \"n5\".");
				ta.setEditable(false);
				ta.setWrapText(true);
				alert.getDialogPane().setContent(ta);
				alert.show();
			}
		}
		catch (final IOException e) {
			LOG.error("Failed to notify about invalid N5 container: {}", updatedRoot.getAbsolutePath(), e);
		}

		if (updatedRoot != null && updatedRoot.exists() && updatedRoot.isDirectory()) {
			// set null first to make sure that container will be invalidated even if directory is the same
			container.set(null);
			container.set(updatedRoot.getAbsolutePath());
		}

	}
 
Example 11
Source File: WebmapKeywordSearchController.java    From arcgis-runtime-samples-java with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 12
Source File: PDFPagesRender.java    From PDF4Teachers with Apache License 2.0 5 votes vote down vote up
public static void renderAdvertisement(){
	if(MainWindow.mainScreen.hasDocument(false)){
		if(!MainWindow.mainScreen.document.pdfPagesRender.advertisement){ // not already sended
			MainWindow.mainScreen.document.pdfPagesRender.advertisement = true;

			Alert alert = Builders.getAlert(Alert.AlertType.WARNING, TR.tr("Erreur de rendu"));
			alert.setHeaderText(TR.tr("Des erreurs sont apparues lors du rendu du document PDF."));
			alert.setContentText(TR.tr("Certains caractères spéciaux (espaces insécables, signes spéciaux ou tabulations) risquent de ne pas s'afficher correctement."));
			alert.show();
		}
	}
}
 
Example 13
Source File: DialogLoggerUtil.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * shows a message dialog just for a few given milliseconds
 *
 * @param parent
 * @param title
 * @param message
 * @param time
 */
public static void showMessageDialogForTime(String title, String message, long time) {
  Alert alert = new Alert(AlertType.INFORMATION, message);
  alert.setTitle(title);
  alert.show();
  Timeline idleTimer = new Timeline(new KeyFrame(Duration.millis(time), e -> alert.hide()));
  idleTimer.setCycleCount(1);
  idleTimer.play();
}
 
Example 14
Source File: AlertUtil.java    From Spring-generator with MIT License 4 votes vote down vote up
/**
 * 信息提示框
 * 
 * @param message
 */
public static void showInfoAlert(String message) {
	Alert alert = new Alert(Alert.AlertType.INFORMATION);
	alert.setContentText(message);
	alert.show();
}
 
Example 15
Source File: AlertUtil.java    From Spring-generator with MIT License 4 votes vote down vote up
/**
 * 注意提示框
 * 
 * @param message
 */
public static void showWarnAlert(String message) {
	Alert alert = new Alert(Alert.AlertType.WARNING);
	alert.setContentText(message);
	alert.show();
}
 
Example 16
Source File: AlertUtil.java    From Spring-generator with MIT License 4 votes vote down vote up
/**
 * 异常提示框
 * 
 * @param message
 */
public static void showErrorAlert(String message) {
	Alert alert = new Alert(Alert.AlertType.ERROR);
	alert.setContentText(message);
	alert.show();
}
 
Example 17
Source File: AuthenticationDialog.java    From arcgis-runtime-samples-java with Apache License 2.0 4 votes vote down vote up
private void showMessage(String message) {
  Alert alert = new Alert(Alert.AlertType.ERROR);
  alert.initOwner(this.getOwner());
  alert.setContentText(message);
  alert.show();
}
 
Example 18
Source File: AlertUtil.java    From Vert.X-generator with MIT License 4 votes vote down vote up
/**
 * 信息提示框
 * 
 * @param message
 */
public static void showInfoAlert(String message) {
	Alert alert = new Alert(Alert.AlertType.INFORMATION);
	alert.setContentText(message);
	alert.show();
}
 
Example 19
Source File: AlertUtil.java    From Vert.X-generator with MIT License 4 votes vote down vote up
/**
 * 注意提示框
 * 
 * @param message
 */
public static void showWarnAlert(String message) {
	Alert alert = new Alert(Alert.AlertType.WARNING);
	alert.setContentText(message);
	alert.show();
}
 
Example 20
Source File: AlertUtil.java    From Vert.X-generator with MIT License 4 votes vote down vote up
/**
 * 异常提示框
 * 
 * @param message
 */
public static void showErrorAlert(String message) {
	Alert alert = new Alert(Alert.AlertType.ERROR);
	alert.setContentText(message);
	alert.show();
}