Java examples for JavaFX:Dialog
show JavaFX Exception Dialog
import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Label; import javafx.scene.control.TextArea; import javafx.scene.layout.GridPane; import javafx.scene.layout.Priority; import java.io.PrintWriter; import java.io.StringWriter; public class Main{ public static void showExceptionDialog(Throwable throwable) { throwable.printStackTrace();/*w ww. j a va2s. c o m*/ Alert alert = new Alert(AlertType.ERROR); alert.setTitle("DevLaunch Dialog"); alert.setHeaderText("Thrown Exception"); alert.setContentText("DevLaunch has thrown an exception."); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); throwable.printStackTrace(pw); String exceptionText = sw.toString(); Label label = new Label("The exception stacktrace was:"); 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(); } }