Example usage for javafx.scene.control DialogPane getStylesheets

List of usage examples for javafx.scene.control DialogPane getStylesheets

Introduction

In this page you can find the example usage for javafx.scene.control DialogPane getStylesheets.

Prototype

public final ObservableList<String> getStylesheets() 

Source Link

Document

Gets an observable list of string URLs linking to the stylesheets to use with this Parent's contents.

Usage

From source file:UI.MainStageController.java

/**
 * creates the file not found alert box/*w  w  w.j av a2s  . c om*/
 */
private void fileNotFoundAlertBox() {
    fileNotFoundAlert = new Alert(Alert.AlertType.ERROR);
    fileNotFoundAlert.setTitle("File not found");
    fileNotFoundAlert.setHeaderText("File not found");
    fileNotFoundAlert.setContentText("Could not find the file you were looking for");

    //style the alert
    DialogPane dialogPane = fileNotFoundAlert.getDialogPane();
    dialogPane.getStylesheets().add("/UI/alertStyle.css");

    Exception fileNotFoundException = new FileNotFoundException("Could not find your selected file");

    //create expandable exception
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    fileNotFoundException.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);

    // Set expandable Exception into the dialog pane.
    fileNotFoundAlert.getDialogPane().setExpandableContent(expContent);
    fileNotFoundAlert.showAndWait();
}