Example usage for javafx.fxml FXMLLoader load

List of usage examples for javafx.fxml FXMLLoader load

Introduction

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

Prototype

public <T> T load() throws IOException 

Source Link

Document

Loads an object hierarchy from a FXML document.

Usage

From source file:ninja.eivind.hotsreplayuploader.window.nodes.UploaderNode.java

@Autowired
public UploaderNode(FXMLLoaderFactory factory) throws IOException {
    super();//  w w  w.j a  v  a 2s.co  m
    URL resource = getClass().getResource("UploaderNode.fxml");
    FXMLLoader loader = factory.get();
    loader.setLocation(resource);
    loader.setRoot(this);
    loader.setController(this);
    loader.load();
}

From source file:aajavafx.MedicinesController.java

@FXML
private void handleBackButton(ActionEvent event) {
    try {//w  w w  .  j ava  2  s  .  c  o m

        Node node = (Node) event.getSource();
        Stage stage = (Stage) node.getScene().getWindow();

        FXMLLoader loader = new FXMLLoader(getClass().getResource("MainPage.fxml"));
        Parent root = loader.load();

        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();

        System.out.println("You clicked Schedule!");
    } catch (Exception ex) {

        System.out.println("ERROR! " + ex);
    }

}

From source file:aajavafx.LoginController.java

@FXML
private void handleButtonLoginAction(ActionEvent event) {

    try {/* w  ww.j  a va2 s.  c  o m*/

        username_var = userID.getText().toString();
        password_var = passwordID.getText().toString();
        Kripto myKripto = new Kripto();
        System.out.println(myKripto.encrypt(password_var));

        if (saveCredentials.isSelected()) {
            UserCredentials userCred = new UserCredentials(username_var, password_var);
            try (ObjectOutputStream out = new ObjectOutputStream(Files.newOutputStream(savedCredentials))) {
                out.writeObject(userCred);
            } catch (IOException ex) {
                System.out.println("IO Exception: " + ex);
            } catch (Exception ex) {
                System.out.println("Exception: " + ex);
                ;
            }
        }

        //////Check password disabled 

        //  String passwordCypherFromDB = getPassword(username_var);
        //  String passwordFromDB = myKripto.decrypt(passwordCypherFromDB);
        //   if (passwordFromDB.equals(password_var)) {
        Node node = (Node) event.getSource();
        Stage stage = (Stage) node.getScene().getWindow();

        FXMLLoader loader = new FXMLLoader(getClass().getResource("MainPageTab.fxml"));
        Parent root = loader.load();

        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();

        System.out.println("Taking you to next page!");
        //  } else {
        //     outputmessageID.setText("Login failed!!!!");
        // }
    } catch (Exception ex) {
        System.out.println("LOAD PAGE EXCEPTION: " + ex);
    }

    System.out.println("You clicked me!");

}

From source file:dbsdemo.RegistrationWindowController.java

public void goToMainWindowScene(User user) {
    // Load properties file - TODO catch exception
    Properties prop = PropLoader.load("etc/config.properties");
    // Continue to main window screen
    try {// w w  w  . j ava  2 s .  c  o m
        FXMLLoader loader = new FXMLLoader(getClass().getResource(prop.getProperty("MainWindowPath")));
        Parent root = (Parent) loader.load();

        MainWindowController mainWindowController = loader.getController();
        mainWindowController.setActiveUser(user);

        //Scene scene = new Scene(root);
        Stage mainWindowStage = new Stage();
        mainWindowStage.setTitle("Fuel database");
        mainWindowStage.setMinHeight(mainWindowStage.getHeight());
        mainWindowStage.setMinWidth(mainWindowStage.getWidth());
        mainWindowStage.setScene(new Scene(root));

        mainWindowStage.show();
    } catch (IOException ex) {
        Logger.getLogger(LoginWindowController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:net.rptools.gui.GuiBuilder.java

/**
 * Construct the scene in this contructor and later publish on the
 * application thread.// w  w w.  j  ava 2s . co  m
 * @param parent component back-reference
 */
public GuiBuilder(final GuiComponentImpl parent) {
    component = parent;
    // Basic initialization
    rootStage = new Stage();
    final FXMLLoader fxmlLoader = new GuiFXMLLoader("main.fxml");
    try {
        rootRegion = (Region) fxmlLoader.load();
    } catch (final IOException e) {
        LOGGER.error("GUI can't be constructed", e);
    }
    fxmlListener = fxmlLoader.getController();
}

From source file:jlotoprint.MainViewController.java

@FXML
public void handleOpenTemplateDesigner(ActionEvent event) {

    try {//from w  w  w  .j ava  2  s .c  o m
        FXMLLoader dialog = new FXMLLoader(MainViewController.class.getResource("TemplateDesigner.fxml"));
        Parent root = (Parent) dialog.load();
        final Stage stage = new Stage();
        stage.setOnCloseRequest((WindowEvent windowEvent) -> {
            boolean shouldClose = ((TemplateDesignerController) dialog.getController()).showSaveChangesDialog();
            //cancel event
            if (!shouldClose) {
                windowEvent.consume();
            }
        });
        root.addEventHandler(TemplateDesignerEvent.CLOSE, actionEvent -> {
            stage.close();
        });
        stage.setScene(new Scene(root));
        stage.getIcons().add(new Image("file:resources/icon.png"));
        stage.setTitle("Template Designer");
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.initOwner(JLotoPrint.stage.getScene().getWindow());
        stage.show();
    } catch (IOException ex) {
        Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:application.Main.java

@Override
public void start(Stage primaryStage) throws InterruptedException {

    System.out.println(applicationTitle + " initialized!");

    // define working variables
    String text = "";
    Boolean terminateExecution = Boolean.FALSE;

    // does the specified FXML XML file path exist?
    String fxmlXmlFileFullPath = fxmlPath.equals("") ? fxmlXmlFileName : fxmlPath + "/" + fxmlXmlFileName;
    URL urlXml = Main.class.getResource(fxmlXmlFileFullPath);
    if (urlXml == null) {
        terminateExecution = Boolean.TRUE;
        text = Main.class.getName() + ": FXML XML File '" + fxmlXmlFileFullPath
                + "' not found in resource path!";
        GenericUtilities.outputToSystemErr(text, systemErrorsDesired);
    }/*from   w w  w . jav a2 s . com*/

    // does the specified FXML CSS file path exist?
    String fxmlCssFileFullPath = fxmlPath.equals("") ? fxmlCssFileName : fxmlPath + "/" + fxmlCssFileName;
    URL urlCss = Main.class.getResource(fxmlCssFileFullPath);
    if (urlCss == null) {
        terminateExecution = Boolean.TRUE;
        text = Main.class.getName() + ": FXML CSS File '" + fxmlCssFileFullPath
                + "' not found in resource path!";
        GenericUtilities.outputToSystemErr(text, systemErrorsDesired);
    }

    if (terminateExecution) {
        text = Main.class.getName() + ": Execution terminated due to errors!";
        GenericUtilities.outputToSystemErr(text, systemErrorsDesired);
        GenericUtilities.outputToSystemOut(text, systemOutputDesired);
        return;
    }

    // initialize and display the primary stage
    try {
        // load the FXML file and instantiate the "root" object
        FXMLLoader fxmlLoader = new FXMLLoader(urlXml);
        Parent root = (Parent) fxmlLoader.load();

        controller = (FracKhemGUIController) fxmlLoader.getController();
        controller.setStage(primaryStage);
        controller.setInitStageTitle(applicationTitle);

        // initialize and display the stage
        createTrayIcon(primaryStage);
        firstTime = Boolean.TRUE;
        Platform.setImplicitExit(Boolean.FALSE);

        Scene scene = new Scene(root);
        scene.getStylesheets().add(urlCss.toExternalForm());
        primaryStage.setScene(scene);
        primaryStage.setTitle(applicationTitle + " - " + controller.getPropFileCurrFileVal());
        primaryStage.show();
    } catch (Exception e) {
        text = ExceptionUtils.getStackTrace(e);
        GenericUtilities.outputToSystemErr(text, systemErrorsDesired);
        text = Main.class.getName() + ": Execution terminated due to errors!";
        GenericUtilities.outputToSystemErr(text, systemErrorsDesired);
        GenericUtilities.outputToSystemOut(text, systemOutputDesired);
    }

}

From source file:de.mirkosertic.desktopsearch.DesktopSearch.java

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

    // This is our base directory
    File theBaseDirectory = new File(SystemUtils.getUserHome(), "FreeSearchIndexDir");
    theBaseDirectory.mkdirs();/*from www.  j a  va 2s  .  c o m*/

    configurationManager = new ConfigurationManager(theBaseDirectory);

    Notifier theNotifier = new Notifier();

    stage = aStage;

    // Create the known preview processors
    PreviewProcessor thePreviewProcessor = new PreviewProcessor();

    try {
        // Boot the search backend and set it up for listening to configuration changes
        backend = new Backend(theNotifier, configurationManager.getConfiguration(), thePreviewProcessor);
        configurationManager.addChangeListener(backend);

        // Boot embedded JSP container
        embeddedWebServer = new FrontendEmbeddedWebServer(aStage, backend, thePreviewProcessor,
                configurationManager);

        embeddedWebServer.start();
    } catch (BindException | LockReleaseFailedException | LockObtainFailedException e) {
        // In this case, there is already an instance of DesktopSearch running
        // Inform the instance to bring it to front end terminate the current process.
        URL theURL = new URL(FrontendEmbeddedWebServer.getBringToFrontUrl());
        // Retrieve the content, but it can be safely ignored
        // There must only be the get request
        Object theContent = theURL.getContent();

        // Terminate the JVM. The window of the running instance is visible now.
        System.exit(0);
    }

    aStage.setTitle("Free Desktop Search");
    aStage.setWidth(800);
    aStage.setHeight(600);
    aStage.initStyle(StageStyle.TRANSPARENT);

    FXMLLoader theLoader = new FXMLLoader(getClass().getResource("/scenes/mainscreen.fxml"));
    AnchorPane theMainScene = theLoader.load();

    final DesktopSearchController theController = theLoader.getController();
    theController.configure(this, backend, FrontendEmbeddedWebServer.getSearchUrl(), stage.getOwner());

    Undecorator theUndecorator = new Undecorator(stage, theMainScene);
    theUndecorator.getStylesheets().add("/skin/undecorator.css");

    Scene theScene = new Scene(theUndecorator);

    // Hacky, but works...
    theUndecorator.setStyle("-fx-background-color: rgba(0, 0, 0, 0);");

    theScene.setFill(Color.TRANSPARENT);
    aStage.setScene(theScene);

    aStage.getIcons().add(new Image(getClass().getResourceAsStream("/fds.png")));

    if (SystemTray.isSupported()) {
        Platform.setImplicitExit(false);
        SystemTray theTray = SystemTray.getSystemTray();

        // We need to reformat the icon according to the current tray icon dimensions
        // this depends on the underlying OS
        java.awt.Image theTrayIconImage = Toolkit.getDefaultToolkit()
                .getImage(getClass().getResource("/fds_small.png"));
        int trayIconWidth = new TrayIcon(theTrayIconImage).getSize().width;
        TrayIcon theTrayIcon = new TrayIcon(
                theTrayIconImage.getScaledInstance(trayIconWidth, -1, java.awt.Image.SCALE_SMOOTH),
                "Free Desktop Search");
        theTrayIcon.setImageAutoSize(true);
        theTrayIcon.setToolTip("FXDesktopSearch");
        theTrayIcon.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 1) {
                    Platform.runLater(() -> {
                        if (stage.isIconified()) {
                            stage.setIconified(false);
                        }
                        stage.show();
                        stage.toFront();
                    });
                }
            }
        });
        theTray.add(theTrayIcon);

        aStage.setOnCloseRequest(aEvent -> stage.hide());
    } else {

        aStage.setOnCloseRequest(aEvent -> shutdown());
    }

    aStage.setMaximized(true);
    aStage.show();
}

From source file:spdxedit.externalRef.ExternalRefListControl.java

public AnchorPane getUi() {
    try {//from w w w . j  a  v a  2s  . c  o m
        FXMLLoader loader = new FXMLLoader(ExternalRefListControl.class.getResource("/ExternalRefList.fxml"));
        loader.setController(this);
        AnchorPane pane = loader.load();
        return pane;
    } catch (IOException ioe) {
        throw new RuntimeException("Unable to load scene for License editor dialog");
    }
}

From source file:io.uploader.drive.auth.webbrowser.SimpleBrowserImpl.java

public SimpleBrowserImpl(Stage stage, String url) throws IOException {

    super();/*  w w  w.  ja v  a2 s.  com*/

    Preconditions.checkNotNull(stage);

    this.stage = stage;
    stage.setTitle("Drive Uploader - Authentication");
    UiUtils.setStageAppSize(stage);
    Scene scene = new Scene(new Group());

    AnchorPane root = new AnchorPane();

    final WebView browser = new WebView();
    webEngine = browser.getEngine();

    /*
    Menu settingsMenu = new Menu ("Settings") ;
    MenuItem proxy = new MenuItem ("Proxy") ;
    settingsMenu.getItems().add(proxy) ;
    MenuBar menuBar = new MenuBar () ;
    menuBar.getMenus().add(settingsMenu) ;
    proxy.setOnAction(new EventHandler<ActionEvent> () {
            
     @Override
     public void handle(ActionEvent event) {
    try {
       ProxySettingDialog dlg = new ProxySettingDialog (stage, Configuration.INSTANCE) ;
       dlg.showDialog();
    } catch (IOException e) {
       logger.error("Error occurred while opening the proxy setting dialog", e);
    }
     }});*/

    FXMLLoader mainMenuLoader = new FXMLLoader(getClass().getResource("/fxml/MainMenu.fxml"));
    VBox mainMenuBar = (VBox) mainMenuLoader.load();
    AnchorPane.setTopAnchor(mainMenuBar, 0.0);
    AnchorPane.setLeftAnchor(mainMenuBar, 0.0);
    AnchorPane.setRightAnchor(mainMenuBar, 0.0);
    MainMenuController mainMenuController = mainMenuLoader.<MainMenuController>getController();
    mainMenuController.setOwner(stage);
    mainMenuController.setConfiguration(Configuration.INSTANCE);
    mainMenuController.hideAccountMenu(true);

    ScrollPane scrollPane = new ScrollPane();
    scrollPane.setContent(browser);
    scrollPane.setFitToWidth(true);
    scrollPane.setFitToHeight(true);

    if (StringUtils.isNotEmpty(url)) {
        goTo(url);
    }

    if (DriveUploader.isMacOsX()) {
        AnchorPane.setTopAnchor(scrollPane, 5.0);
    } else {
        AnchorPane.setTopAnchor(scrollPane, 35.0);
    }
    AnchorPane.setLeftAnchor(scrollPane, 5.0);
    AnchorPane.setRightAnchor(scrollPane, 5.0);
    AnchorPane.setBottomAnchor(scrollPane, 5.0);

    root.getChildren().add(mainMenuBar);
    root.getChildren().addAll(scrollPane);
    scene.setRoot(root);

    stage.setScene(scene);
}