create JavaFX Information Dialog - Java JavaFX

Java examples for JavaFX:Dialog

Description

create JavaFX Information Dialog

Demo Code


import javafx.scene.control.Alert;
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 final Alert createInformationDialog(
            Alert.AlertType alertType, String headerText, String info) {
        Alert alert = new Alert(alertType);
        Label label = new Label(headerText);
        TextArea textArea = new TextArea(info);
        textArea.setEditable(false);/*  w  w  w  .jav a  2s .  co  m*/
        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.getDialogPane().setExpanded(true);
        return alert;
    }
}

Related Tutorials