All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.diirt.javafx.tools.JavaFXLaunchUtil Maven / Gradle / Ivy

There is a newer version: 3.1.7
Show newest version
/**
 * Copyright (C) 2010-14 diirt developers. See COPYRIGHT.TXT
 * All rights reserved. Use is subject to license terms. See LICENSE.TXT
 */
package org.diirt.javafx.tools;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

/**
 *
 * @author carcassi
 */
public class JavaFXLaunchUtil {
    
    private JavaFXLaunchUtil() {
        // No instances allowed
    }
    
    public static void launch(String title, Class rootClass, String... args) {
        appTitle = title;
        appRootClass = rootClass;
        SimpleApplication.launch(SimpleApplication.class, args);
    }

    public static void open(String title, Class rootClass) {
        try {
            Stage stage = new Stage();
            stage.setTitle(title);
            stage.setScene(new Scene(rootClass.newInstance()));
            stage.show();
        } catch (InstantiationException | IllegalAccessException instantiationException) {
            // TODO put an Alert, but requires jdk 8u40
        }
    }
    
    private static volatile String appTitle;
    private static volatile Class appRootClass;
    
    public static class SimpleApplication extends Application {
        @Override
        public void start(Stage primaryStage) throws Exception {
            primaryStage.setTitle(appTitle);
            Scene scene = new Scene(appRootClass.newInstance());
            primaryStage.setScene(scene);
            primaryStage.show();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy