do JavaFX Modal Dialog - Java JavaFX

Java examples for JavaFX:Dialog

Description

do JavaFX Modal Dialog

Demo Code


//package com.java2s;

import javafx.scene.Scene;

import javafx.scene.layout.Pane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class Main {
    public static void doModal(Pane p, Stage parentStage) {
        Stage modal_dialog = new Stage(StageStyle.UNDECORATED);
        modal_dialog.initModality(Modality.WINDOW_MODAL);
        modal_dialog.initOwner(parentStage);

        p.getStylesheets().add("com/sciaps/utils/resources/Modal.css");

        Scene scene = new Scene(p);

        modal_dialog.setScene(scene);//from   ww w .j  ava  2 s  .c om

        p.setPrefHeight(parentStage.getHeight() - 50);
        p.setPrefWidth(parentStage.getWidth() - 50);
        p.setMaxHeight(parentStage.getHeight() - 50);
        p.setMaxWidth(parentStage.getWidth() - 50);

        modal_dialog.showAndWait();
    }
}

Related Tutorials