Java examples for JavaFX:Dialog
Show JavaFX Error Dialog
//package com.java2s; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.VBoxBuilder; import javafx.stage.Modality; import javafx.stage.Stage; import javafx.stage.Window; public class Main { public static void ShowErrorDialog(Window parent, String errorMessage) { final Stage err = new Stage(); err.initModality(Modality.WINDOW_MODAL); err.initOwner(parent);//ww w . j a v a 2 s. c o m err.setResizable(false); VBoxBuilder<?> rt = VBoxBuilder.create(); Label lbl = new Label(errorMessage); Button close = new Button("Ok"); close.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { err.close(); } }); rt.alignment(Pos.CENTER); rt.padding(new Insets(16)); rt.children(lbl, close); rt.spacing(10); err.setScene(new Scene(rt.build())); if (parent != null) { err.getScene().getStylesheets() .addAll(parent.getScene().getStylesheets()); } err.show(); } }