Example usage for javafx.fxml FXMLLoader setClassLoader

List of usage examples for javafx.fxml FXMLLoader setClassLoader

Introduction

In this page you can find the example usage for javafx.fxml FXMLLoader setClassLoader.

Prototype

public void setClassLoader(ClassLoader classLoader) 

Source Link

Document

Sets the classloader used by this loader and clears any existing imports.

Usage

From source file:net.noctuasource.noctua.core.ui.ExceptionDialog.java

protected ExceptionDialog(Exception exception) {
    this.exception = exception;

    VBox root = new VBox();

    stage = new Stage();
    stage.initModality(Modality.APPLICATION_MODAL);
    stage.setTitle("Exception");
    Scene scene = new Scene(root);
    scene.getStylesheets().add(getClass().getResource(CSS_FILE).toExternalForm());
    stage.setScene(scene);/*w w  w  . j  a  va  2s .c o m*/

    FXMLLoader loader = new FXMLLoader();
    loader.setClassLoader(getClass().getClassLoader());
    loader.setController(this);
    loader.setLocation(getClass().getResource(FXML_FILE));

    try {
        Node node = (Node) loader.load();
        root.getChildren().add(node);
        VBox.setVgrow(node, Priority.ALWAYS);
    } catch (IOException e) {
        logger.error("Error while creating view: ", e);
        stage.close();
        return;
    }

    messageField.setText(exception.getLocalizedMessage());
    fullExceptionField.setText(ExceptionUtils.getFullStackTrace(exception));

    //stage.sizeToScene();
    stage.centerOnScreen();
    stage.show();
}

From source file:acmi.l2.clientmod.xdat.XdatEditor.java

@Override
public void start(Stage primaryStage) throws Exception {
    this.stage = primaryStage;

    FXMLLoader loader = new FXMLLoader(getClass().getResource("main.fxml"), interfaceResources);
    loader.setClassLoader(getClass().getClassLoader());
    loader.setControllerFactory(param -> new Controller(XdatEditor.this));
    Parent root = loader.load();//from   w ww. jav a  2  s .  co  m
    controller = loader.getController();

    primaryStage.setTitle("XDAT Editor");
    primaryStage.setScene(new Scene(root));
    primaryStage.show();

    postShow();
}

From source file:fx.browser.Window.java

public void setLocation(String location) throws URISyntaxException {
    System.out.println("# " + this.toString() + "-Classloader: " + getClass().getClassLoader().toString()
            + " setLocation()");
    this.location = location;
    HttpGet httpGet = new HttpGet(new URI(location));

    try (CloseableHttpResponse response = Browser.getHttpClient().execute(httpGet)) {
        switch (response.getStatusLine().getStatusCode()) {

        case HttpStatus.SC_OK:
            FXMLLoader loader = new FXMLLoader();
            Header header = response.getFirstHeader("class-loader-url");

            if (header != null) {
                URL url = new URL(location);

                url = new URL(url.getProtocol(), url.getHost(), url.getPort(), header.getValue());
                if (logger.isLoggable(Level.INFO)) {
                    logger.log(Level.INFO, "Set up remote classloader: {0}", url);
                }/*ww w.ja va 2s  . c  o  m*/

                loader.setClassLoader(HttpClassLoader.getInstance(url, getClass().getClassLoader()));
            }

            try {
                ByteArrayOutputStream buffer = new ByteArrayOutputStream();

                response.getEntity().writeTo(buffer);
                response.close();
                setContent(loader.load(new ByteArrayInputStream(buffer.toByteArray())));
            } catch (Exception e) {
                response.close();
                logger.log(Level.INFO, e.toString(), e);
                Node node = loader.load(getClass().getResourceAsStream("/fxml/webview.fxml"));
                WebViewController controller = (WebViewController) loader.getController();

                controller.view(location);
                setContent(node);
            }

            break;

        case HttpStatus.SC_UNAUTHORIZED:
            response.close();
            Optional<Pair<String, String>> result = new LoginDialog().showAndWait();

            if (result.isPresent()) {
                URL url = new URL(location);

                Browser.getCredentialsProvider().setCredentials(new AuthScope(url.getHost(), url.getPort()),
                        new UsernamePasswordCredentials(result.get().getKey(), result.get().getValue()));
                setLocation(location);
            }

            break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:acmi.l2.clientmod.xdat.Controller.java

private Node loadScriptTabContent() {
    try {/*www . j a  v  a 2 s . c  om*/
        FXMLLoader loader = new FXMLLoader(getClass().getResource("scripting/main.fxml"));
        loader.setClassLoader(getClass().getClassLoader());
        loader.setControllerFactory(param -> new acmi.l2.clientmod.xdat.scripting.Controller(editor));
        return wrap(loader.load());
    } catch (IOException e) {
        log.log(Level.WARNING, "Couldn't load script console", e);
    }
    return null;
}

From source file:org.sleuthkit.autopsy.imageanalyzer.FXMLConstructor.java

static public void construct(Node n, String fxmlFileName) {
    final String name = "nbres:/" + StringUtils.replace(n.getClass().getPackage().getName(), ".", "/") + "/"
            + fxmlFileName;/*from  ww w  .j  a v  a 2 s . co  m*/
    //        System.out.println(name);

    try {
        FXMLLoader fxmlLoader = new FXMLLoader(new URL(name));
        fxmlLoader.setRoot(n);
        fxmlLoader.setController(n);

        try {
            fxmlLoader.load();
        } catch (IOException exception) {
            try {
                fxmlLoader.setClassLoader(FXMLLoader.getDefaultClassLoader());
                fxmlLoader.load();
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    } catch (MalformedURLException ex) {
        Exceptions.printStackTrace(ex);
    }

}

From source file:org.sleuthkit.autopsy.timeline.FXMLConstructor.java

static public void construct(Node n, String fxmlFileName) {
    final String name = "nbres:/" + StringUtils.replace(n.getClass().getPackage().getName(), ".", "/") + "/"
            + fxmlFileName; // NON-NLS
    System.out.println(name);/*from  w w w.j ava 2 s  .  com*/

    try {
        FXMLLoader fxmlLoader = new FXMLLoader(new URL(name));
        fxmlLoader.setRoot(n);
        fxmlLoader.setController(n);

        try {
            fxmlLoader.load();
        } catch (IOException exception) {
            try {
                fxmlLoader.setClassLoader(FXMLLoader.getDefaultClassLoader());
                fxmlLoader.load();
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    } catch (MalformedURLException ex) {
        Exceptions.printStackTrace(ex);
    }
}