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:aajavafx.VisitorScheduleController.java

@FXML
private void handleBackButton(ActionEvent event) {
    try {//  www .j av a  2s .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, 879, 599);
        stage.setScene(scene);

        stage.setTitle("Main menu");
        stage.show();

    } catch (Exception ex) {
        Logger.getLogger(MainPageController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:mesclasses.view.TimetableController.java

private Cours openEditDialog(Cours coursToEdit, Cours originalCours) {
    try {//from   w w  w.j a va 2 s.c om
        // Load the fxml file and create a new stage for the popup dialog.
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(MainApp.class.getResource(Constants.COURS_EDIT_DIALOG));
        AnchorPane page = (AnchorPane) loader.load();

        // Create the dialog Stage.
        Stage dialogStage = new Stage();
        dialogStage.setTitle("Edition d'un cours");
        dialogStage.initModality(Modality.WINDOW_MODAL);
        dialogStage.initOwner(primaryStage);
        Scene scene = new Scene(page);
        dialogStage.setScene(scene);

        // Set the person into the controller.
        CoursEditDialogController controller = loader.getController();
        controller.setDialogStage(dialogStage);
        controller.setCours(coursToEdit, false);

        // Show the dialog and wait until the user closes it
        dialogStage.showAndWait();
        int status = controller.getStatus();
        if (status >= 0) {
            //update/cancel
            return controller.getCours();
        } else {
            //delete
            getPane(coursToEdit).getChildren().remove(coursToEdit.getEvent());
            int seances = model.delete(originalCours).size();
            ModalUtil.info("Sances modifies", seances + " sances ont t modifies");
            return null;
        }

    } catch (IOException e) {
        notif(e);
        return null;
    }
}

From source file:aajavafx.VisitorController.java

@FXML
private void handleGoBack(ActionEvent event) {
    try {/*from  ww w .  j  ava 2 s. c om*/
        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, 879, 599);
        stage.setScene(scene);

        stage.setTitle("Main menu");
        stage.show();

    } catch (Exception ex) {
        Logger.getLogger(MainPageController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:aajavafx.CustomerMedicineController.java

@FXML
private void handleBackButton(ActionEvent event) {
    try {//from   ww  w .  j ava  2s . c  om

        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("You clicked Schedule!");
    } catch (Exception ex) {

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

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

/**
 * Common Private Constructor// w  ww. j av a  2s .  c  om
 *
 * @param controller The controller for this Dialog.
 * @param eventIDS   A List of eventIDs to present to the user to choose
 *                   from.
 */
@NbBundle.Messages({
        "ShowInTimelineDialog.amountValidator.message=The entered amount must only contain digits." })
private ShowInTimelineDialog(TimeLineController controller, List<Long> eventIDS) {
    this.controller = controller;

    //load dialog content fxml
    final String name = "nbres:/"
            + StringUtils.replace(ShowInTimelineDialog.class.getPackage().getName(), ".", "/")
            + "/ShowInTimelineDialog.fxml"; // NON-NLS
    try {
        FXMLLoader fxmlLoader = new FXMLLoader(new URL(name));
        fxmlLoader.setRoot(contentRoot);
        fxmlLoader.setController(this);

        fxmlLoader.load();
    } catch (IOException ex) {
        LOGGER.log(Level.SEVERE, "Unable to load FXML, node initialization may not be complete.", ex); //NON-NLS
    }
    //assert that fxml loading happened correctly
    assert eventTable != null : "fx:id=\"eventTable\" was not injected: check your FXML file 'ShowInTimelineDialog.fxml'.";
    assert typeColumn != null : "fx:id=\"typeColumn\" was not injected: check your FXML file 'ShowInTimelineDialog.fxml'.";
    assert dateTimeColumn != null : "fx:id=\"dateTimeColumn\" was not injected: check your FXML file 'ShowInTimelineDialog.fxml'.";
    assert amountSpinner != null : "fx:id=\"amountsSpinner\" was not injected: check your FXML file 'ShowInTimelineDialog.fxml'.";
    assert unitComboBox != null : "fx:id=\"unitChoiceBox\" was not injected: check your FXML file 'ShowInTimelineDialog.fxml'.";

    //validat that spinner has a integer in the text field.
    validationSupport.registerValidator(amountSpinner.getEditor(), false, Validator.createPredicateValidator(
            NumberUtils::isDigits, Bundle.ShowInTimelineDialog_amountValidator_message()));

    //configure dialog properties
    PromptDialogManager.setDialogIcons(this);
    initModality(Modality.APPLICATION_MODAL);

    //add scenegraph loaded from fxml to this dialog.
    DialogPane dialogPane = getDialogPane();
    dialogPane.setContent(contentRoot);
    //add buttons to dialog
    dialogPane.getButtonTypes().setAll(SHOW, ButtonType.CANCEL);

    ///configure dialog controls
    amountSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 1000));
    amountSpinner.getValueFactory().setConverter(new IntegerStringConverter() {
        /**
         * Convert the String to an Integer using Integer.valueOf, but if
         * that throws a NumberFormatException, reset the spinner to the
         * last valid value.
         *
         * @param string The String to convert
         *
         * @return The Integer value of string.
         */
        @Override
        public Integer fromString(String string) {
            try {
                return super.fromString(string);
            } catch (NumberFormatException ex) {
                return amountSpinner.getValue();
            }
        }
    });

    unitComboBox.setButtonCell(new ChronoFieldListCell());
    unitComboBox.setCellFactory(comboBox -> new ChronoFieldListCell());
    unitComboBox.getItems().setAll(SCROLL_BY_UNITS);
    unitComboBox.getSelectionModel().select(ChronoField.MINUTE_OF_HOUR);

    typeColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getEventType()));
    typeColumn.setCellFactory(param -> new TypeTableCell<>());

    dateTimeColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getStartMillis()));
    dateTimeColumn.setCellFactory(param -> new DateTimeTableCell<>());

    //add events to table
    eventTable.getItems().setAll(
            eventIDS.stream().map(controller.getEventsModel()::getEventById).collect(Collectors.toSet()));
    eventTable.setPrefHeight(Math.min(200, 24 * eventTable.getItems().size() + 28));
}

From source file:aajavafx.Schedule1Controller.java

@FXML
private void handleGoBack(ActionEvent event) {

    try {/*from  ww w . ja v a2 s .c  om*/
        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, 879, 599);
        stage.setScene(scene);

        stage.setTitle("Main menu");
        stage.show();

    } catch (Exception ex) {
        Logger.getLogger(MainPageController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:calendarioSeries.vistas.MainViewController.java

@FXML
private void addNewSerie() {
    Parent root;/*  ww  w.  j ava  2s.co  m*/
    try {
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(MainViewController.class.getResource("NewSerieView.fxml"));
        root = loader.load();

        NewSerieController controller = loader.getController();
        controller.setMainController(this);

        Stage stage = new Stage();
        stage.setTitle("Aade una nueva serie");
        stage.setScene(new Scene(root));
        stage.setMinHeight(650);
        stage.setMinWidth(600);
        stage.setResizable(false);
        stage.show();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:aajavafx.Schedule1Controller.java

@FXML
private void handleGetCustomersUnvisited(ActionEvent event) throws IOException {
    try {/*w  w w  .j ava  2s .c  om*/
        getUnsignedCustomers();
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("UnsignedCustomers.fxml"));
        Parent root1 = (Parent) fxmlLoader.load();
        Stage stage = new Stage();
        stage.setScene(new Scene(root1));
        stage.show();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:aajavafx.CustomerController.java

@FXML
private void handleGoBack(ActionEvent event) {
    //labelError.setText(null);
    try {/*from w ww  . j ava 2s  .co m*/
        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, 879, 599);
        stage.setScene(scene);
        stage.setTitle("Main menu");
        stage.show();
    } catch (Exception ex) {
        Logger.getLogger(MainPageController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ExcelFx.FXMLDocumentController.java

@FXML
private void TablePatch(ActionEvent event) throws IOException {
    System.out.println("ExcelFx.FXMLDocumentController.TablePatch()");
    try {// ww w . j  a  v a  2 s.  co m
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("FileOpenFXML.fxml"));
        Parent root1 = (Parent) fxmlLoader.load();
        Stage stage = new Stage();
        stage.initModality(Modality.WINDOW_MODAL);
        stage.initStyle(StageStyle.DECORATED);
        stage.setTitle(" ");
        stage.setScene(new Scene(root1));
        stage.show();
    } catch (Exception e) {
        System.err.println(e);

    }

}