Display a JavaFX Scene object. - Java JavaFX

Java examples for JavaFX:Scene

Description

Display a JavaFX Scene object.

Demo Code


import javafx.application.ConditionalFeature;
import javafx.application.Platform;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.Window;

public class Main{
    private static volatile Stage stage;
    private static volatile StageStyle stageStyle;
    /**// ww  w .  j av a  2s  .  c o m
     * Display a Scene object. This instantiates a dialog window with the following parameters:
     * @param window A {@link Window} object, representing the parent window.
     * @param title  A {@link String} object, representing the dialog title.
     * @param scene  A {@link Scene} object, representing a displayable scene.
     * @param width  An {@link Integer} value, representing the minimal width.
     * @see DialogUtility
     */
    public static synchronized final void displayContent(Window window,
            String title, Scene scene, int width) {
        DialogUtility.stageCreate(window, stageStyle, title, width);

        stage.setScene(scene);
        stage.showAndWait();
        DialogUtility.stageFinish();
    }
    /**
     * Create a dialog stage. This takes a number of parameterized objects to create an active dialog window.
     * @param w A {@link Window} object, representing the parent window.
     * @param s A {@link StageStyle} object, representing the stage style.
     * @param t A {@link String} object, representing the dialog title.
     * @param i An {@link Integer} value, representing the minimal width.
     * @see DialogUtility
     * @see Modality
     * @see Stage
     * @see StageStyle
     * @see String
     * @see Window
     */
    private static synchronized void stageCreate(Window w, StageStyle s,
            String t, int i) {
        DialogUtility.stageFinish();
        stage = new Stage(s);
        stage.initOwner(w);
        stage.initModality(Modality.WINDOW_MODAL);
        stage.setTitle(t);
        stage.setMinWidth(i);
    }
    /**
     * Dispose of the dialog.
     * @see DialogUtility
     */
    private static synchronized void stageFinish() {
        if (stage != null) {
            stage = null;
        }
    }
}

Related Tutorials