load Root for javafx fxml - Java JavaFX

Java examples for JavaFX:FXML

Description

load Root for javafx fxml

Demo Code


//package com.java2s;
import java.io.IOException;
import java.net.URL;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;

public class Main {
    public static Parent loadRoot(URL fxml) {
        FXMLLoader loader = new FXMLLoader(fxml);
        Parent root = null;/*from   w ww .  ja  va2  s. c o  m*/
        try {
            root = (Parent) loader.load();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return root;
    }

    public static Parent loadRoot(URL fxml, Object controller) {
        FXMLLoader loader = new FXMLLoader(fxml);
        Parent root = null;
        try {
            loader.setController(controller);
            root = (Parent) loader.load();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return root;
    }
}

Related Tutorials