load Convention - Java JavaFX

Java examples for JavaFX:FXML

Description

load Convention

Demo Code


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

public class Main {
    public static Pane loadConvention(Class<?> v) {
        try {//from w ww .  ja va 2  s  .  c om
            return FXMLLoader.load(v.getResource(v.getSimpleName()
                    + ".fxml"));
        } catch (IOException e) {
            throw new RuntimeException();
        }

    }

    public static Pane load(URL fxml, Object controller) {
        FXMLLoader fxmlLoader = new FXMLLoader(fxml);
        fxmlLoader.setController(controller);
        Pane v = null;
        try {
            v = (Pane) fxmlLoader.load();
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException();
        }
        return v;
    }
}

Related Tutorials