JavaFX dialog Error - Java JavaFX

Java examples for JavaFX:Dialog

Description

JavaFX dialog Error

Demo Code


import javafx.event.Event;
import javafx.scene.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.stage.Window;

public class Main{
    public static void dialogError(String msg, Event event) {
        dialogError(msg, getWindowFromEvent(event));
    }/* www .  j a  va2s  . co  m*/
    public static void dialogError(String msg, Window window) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.initOwner(window);
        alert.setTitle("Error");
        alert.setHeaderText(null);
        alert.setContentText(msg);
        alert.show();
    }
    public static Window getWindowFromEvent(Event e) {
        return ((Node) e.getSource()).getScene().getWindow();
    }
}

Related Tutorials