Package javafx.fxml

Examples of javafx.fxml.FXMLLoader


            AquaFx.style();
        } */

        // Load the GUI. The Controller class will be automagically created and wired up.
        URL location = getClass().getResource("main.fxml");
        FXMLLoader loader = new FXMLLoader(location);
        mainUI = loader.load();
        controller = loader.getController();
        // Configure the window with a StackPane so we can overlay things on top of the main UI.
        uiStack = new StackPane(mainUI);
        mainWindow.setTitle(APP_NAME);
        final Scene scene = new Scene(uiStack);
        TextFieldValidator.configureScene(scene);   // Add CSS that we need.
View Full Code Here


    public <T> OverlayUI<T> overlayUI(String name) {
        return evalUnchecked(() -> {
            checkGuiThread();
            // Load the UI from disk.
            URL location = getClass().getResource(name);
            FXMLLoader loader = new FXMLLoader(location);
            Pane ui = loader.load();
            T controller = loader.getController();
            OverlayUI<T> pair = new OverlayUI<>(ui, controller);
            // Auto-magically set the overlayUi member, if it's there.
            controller.getClass().getDeclaredField("overlayUi").set(controller, pair);
            pair.show();
            return pair;
View Full Code Here

        // JavaFX doesn't actually have a standard alert template. Instead the Scene Builder app will create FXML
        // files for an alert window for you, and then you customise it as you see fit. I guess it makes sense in
        // an odd sort of way.
        Stage dialogStage = new Stage();
        dialogStage.initModality(Modality.APPLICATION_MODAL);
        FXMLLoader loader = new FXMLLoader(GuiUtils.class.getResource("alert.fxml"));
        Pane pane = evalUnchecked(() -> (Pane) loader.load());
        AlertWindowController controller = loader.getController();
        setup.accept(dialogStage, controller);
        dialogStage.setScene(new Scene(pane));
        dialogStage.showAndWait();
    }
View Full Code Here

    private void init(Class clazz, String conventionalName) {
        final URL resource = clazz.getResource(conventionalName);
        String bundleName = getBundleName();
        ResourceBundle bundle = getResourceBundle(bundleName);
        this.loader = new FXMLLoader(resource, bundle);
        this.loader.setControllerFactory(new Callback<Class<?>, Object>() {
            @Override
            public Object call(Class<?> p) {
                return InjectionProvider.instantiatePresenter(p);
            }
View Full Code Here

        final String imagePath = ResourceBundle.getBundle(IMAGE_BUNDLE, Languages.getCurrentLocale()).getString(key);
        return new Image(BundleUtils.class.getResource(imagePath).toExternalForm());
    }

    public static FXMLLoader getFXMLLoader(String key) {
        return new FXMLLoader(getFXMLUrl(key), ResourceBundle.getBundle("org.terasology.launcher.bundle.LabelsBundle", Languages.getCurrentLocale()));
    }
View Full Code Here

                                    }
                                });
                                stage.setScene(scene);
                            }

                            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("DebugView.fxml"));
                            TabPane debugView = fxmlLoader.load();
                            debugController = fxmlLoader.getController();
                            final Tab tab = new Tab(xmppSession.getDomain());
                            tab.setContent(debugView);
                            tab.textProperty().bind(title);
                            connectionListenerMap.put(tab, connectionListener);
View Full Code Here

    public PicoFXLoader(MutablePicoContainer pico) {
        this.pico = pico;
    }

    public Parent load(String fxml) {
        FXMLLoader loader = new FXMLLoader(getClass().getResource(fxml));
        loader.setControllerFactory(pico::getComponent);
        try {
            return loader.load();
        } catch (IOException e) {
            throw new UserInterfaceConfigurationException(e);
        }
    }
View Full Code Here

    @Override
    public void start(Stage stage) throws Exception {

        stage.initStyle(StageStyle.TRANSPARENT);

        FXMLLoader parentLoader = new FXMLLoader();
        FXMLLoader tablePopupLoader = new FXMLLoader();

        context = SpringApplication.run(SpringAppConfig.class);
        tablePopupLoader.setControllerFactory(context::getBean);
        parentLoader.setControllerFactory(context::getBean);

        AnchorPane tableAnchor = tablePopupLoader.load(getClass().getResourceAsStream("/fxml/TablePopup.fxml"));
        Parent root = parentLoader.load(getClass().getResourceAsStream("/fxml/Scene.fxml"));
        controller = parentLoader.getController();
        HostServicesDelegate hostServices = HostServicesFactory.getInstance(this);
        controller.setHostServices(hostServices);
View Full Code Here

     */
    public Result load(final URL url, final ResourceBundle resources) throws IOException  {

        fxmlLoadingScope.enter(this);

        final FXMLLoader loader = new FXMLLoader();
        loader.setLocation(url);
        if (resources != null) {
            loader.setResources(resources);
        }
        loader.setBuilderFactory(injector.getInstance(FXMLComponentBuilderFactory.class));
        loader.setControllerFactory(new Callback<Class<?>, Object>() {
            @Override
            public Object call(final Class<?> param) {
                // Use our Guice injector to fetch an instance of the desired
                // controller class
                return param == null ? null : injector.getInstance(param);
            }
        });

        final Node root = (Node) loader.load(url.openStream());

        // Prepares the result that is being returned after loading the FXML hierarchy.
        final Result result = new Result();
        result.location.set(loader.getLocation());
        result.resources.set(loader.getResources());
        result.controller.set(loader.getController());
        result.root.set(root);
        result.charset.set(loader.getCharset());

        fxmlLoadingScope.exit();

        return result;

View Full Code Here

                location = new URL(locationString);
            } catch (final MalformedURLException e) {
                throw new RuntimeException(String.format("Cannot construct URL from string '%s'.", locationString), e);
            }
        }
        final FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(location);
        final String resourcesString = annotation.resources();
        if (!resourcesString.isEmpty()) {
            fxmlLoader.setResources(ResourceBundle.getBundle(resourcesString));
        }
        fxmlLoader.setCharset(Charset.forName(annotation.charset()));
        fxmlLoader.setController(instance);
        fxmlLoader.setRoot(instance);

        // Invoke "fxmlLoader.setTemplate(true)" if we are using JavaFX 8.0 or
        // higher to improve performance on objects that are created multiple times.
        try {
            final Method setTemplateMethod = FXMLLoader.class.getMethod("setTemplate", boolean.class);
            setTemplateMethod.invoke(fxmlLoader, Boolean.TRUE);
        } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            // We simply ignore this exception. It means that we are using
            // a JavaFX runtime prior to JavaFX 8.0.
        }

        // Actual instantiation of the component has to happen on the JavaFX thread.
        // We simply delegate the loading.
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                try {
                    final Object loaded = fxmlLoader.load();
                    if (loaded != instance) {
                        throw new IllegalStateException("Loading of FXML component went terribly wrong! :-(");
                    }
                } catch (final IOException e) {
                    throw new RuntimeException(e);
View Full Code Here

TOP

Related Classes of javafx.fxml.FXMLLoader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.