build JavaFX Exception Dialog - Java JavaFX

Java examples for JavaFX:Dialog

Description

build JavaFX Exception Dialog

Demo Code


import java.io.PrintWriter;
import java.io.StringWriter;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextInputDialog;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;

public class Main{
    public static Alert buildExceptionDialog(String title, String header,
            Exception e) {/* ww w  . j a va 2  s.c  o m*/
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle(title);
        alert.setHeaderText(header);
        Label label = new Label("El rastreo de pila es:");
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        TextArea traceArea = new TextArea(sw.toString());
        traceArea.setEditable(false);
        traceArea.setWrapText(true);
        traceArea.setMaxWidth(Double.MAX_VALUE);
        traceArea.setMaxHeight(Double.MAX_VALUE);
        GridPane.setVgrow(traceArea, Priority.ALWAYS);
        GridPane.setHgrow(traceArea, Priority.ALWAYS);
        GridPane content = new GridPane();
        content.setMaxWidth(Double.MAX_VALUE);
        content.add(label, 0, 0);
        content.add(traceArea, 0, 1);
        alert.getDialogPane().setExpandableContent(content);

        return alert;
    }
}

Related Tutorials