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:com.github.tddts.jet.view.fx.spring.DialogProvider.java

private FXMLLoader loadDialogView(FxDialog dialogAnnotation) {

    String filePath = dialogAnnotation.value();

    if (filePath.isEmpty()) {
        throw new DialogException("@FxDialog should contain path to FXML file!");
    }// w w w  .  j a v a  2 s .c  o m

    FXMLLoader loader = new FXMLLoader(Util.getClasspathResourceURL(filePath),
            resourceBundleProvider.getResourceBundle());

    try {
        loader.load();
    } catch (IOException e) {
        throw new DialogException(e.getMessage(), e);
    }

    return loader;
}

From source file:com.esri.geoevent.test.performance.ui.OrchestratorUI.java

@Override
public void start(Stage primaryStage) {

    Parameters parameters = getParameters();
    Map<String, String> args = parameters.getNamed();
    String modeStr = args.get("mode");
    if (modeStr == null) {
        modeStr = "Orchestrator";
    }/*from  w  w  w . j a va2  s.  c  o m*/
    if (StringUtils.isEmpty(modeStr)) {
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_NULL")
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();
        System.exit(0);
        return;
    }

    Mode mode = Mode.fromValue(modeStr);
    String fxmlFile = "";
    Object controller = null;
    switch (mode) {

    case Orchestrator:
        fxmlFile = "Orchestrator.fxml";
        //controller = new OrchestratorController();
        break;
    default:
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_UNKNOWN", mode)
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();
        System.exit(0);
        return;
    }

    Platform.setImplicitExit(true);
    try {
        FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFile));
        if (controller != null) {
            loader.setController(controller);
        }
        Parent parent = (Parent) loader.load();
        Scene scene = new Scene(parent);

        // set the stage on the orchestrator
        if (loader.getController() instanceof OrchestratorController) {
            OrchestratorController orchestratorController = loader.getController();
            orchestratorController.setStage(primaryStage);
        }

        primaryStage.setOnCloseRequest(new AppCloser());
        primaryStage.setTitle(UIMessages.getMessage("UI_TITLE", mode));
        primaryStage.setScene(scene);
        primaryStage.show();
        OrchestratorUI.primaryStage = primaryStage;
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.ucu.seguridad.views.AbstractFxmlView.java

FXMLLoader loadSynchronously(URL resource, ResourceBundle bundle) throws IllegalStateException {

    FXMLLoader loader = new FXMLLoader(resource, bundle);
    loader.setControllerFactory(this::createControllerForType);

    try {//from w ww.java 2 s .c om
        loader.load();
    } catch (IOException ex) {
        throw new IllegalStateException("Cannot load " + getConventionalName(), ex);
    }

    return loader;
}

From source file:com.coolchick.translatortemplater.Main.java

/**
 * Opens a dialog to edit details for the specified person. If the user clicks OK, the changes
 * are saved into the provided person object and true is returned.
 *
 * @param person the person object to be edited
 * @return true if the user clicked OK, false otherwise.
 *///w w  w  .ja  va2  s.  co  m
public boolean showTranslatorEditDialog(Translator person) {
    try {
        // Load the fxml file and create a new stage for the popup dialog.
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(Main.class.getResource("PersonEditDialog.fxml"));
        AnchorPane page = (AnchorPane) loader.load();
        // Create the dialog Stage.
        Stage dialogStage = new Stage();
        dialogStage.setTitle("Edit Person");
        dialogStage.initModality(Modality.WINDOW_MODAL);
        dialogStage.initOwner(primaryStage);
        Scene scene = new Scene(page);
        dialogStage.setScene(scene);
        // Set the person into the controller.
        PersonEditDialogController controller = loader.getController();
        controller.setDialogStage(dialogStage);
        controller.setMain(this);
        controller.setTranslator(person);
        // Show the dialog and wait until the user closes it
        dialogStage.showAndWait();
        return controller.isOkClicked();
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}

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);//from  ww w.ja  v  a  2s  .  c om

    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:spdxedit.license.LicenseEditControl.java

public Pane getUi() {
    try {//from w  ww.j a  va 2  s .com
        FXMLLoader loader = new FXMLLoader(LicenseEditControl.class.getResource("/LicenseEdit.fxml"));
        loader.setController(this);
        Pane pane = loader.load();
        return pane;
    } catch (IOException ioe) {
        throw new RuntimeException("Unable to load scene for License editor dialog");
    }
}

From source file:org.kordamp.javatrove.example04.view.AppView.java

public Scene createScene() {
    String basename = getClass().getPackage().getName().replace('.', '/') + "/app";
    URL fxml = getClass().getClassLoader().getResource(basename + ".fxml");
    FXMLLoader fxmlLoader = new FXMLLoader(fxml);
    fxmlLoader.setControllerFactory(param -> AppView.this);
    Parent root = null;/*w  w w  .  j  a v  a2  s  .co  m*/
    try {
        root = (Parent) fxmlLoader.load();
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }

    organization.textProperty().addListener((observable, oldValue, newValue) -> {
        model.setState(isBlank(newValue) ? DISABLED : READY);
    });

    model.stateProperty().addListener((observable, oldValue, newValue) -> Platform.runLater(() -> {
        switch (newValue) {
        case DISABLED:
            enabled.setValue(false);
            running.setValue(false);
            break;
        case READY:
            enabled.setValue(true);
            running.setValue(false);
            break;
        case RUNNING:
            enabled.setValue(false);
            running.setValue(true);
            break;
        }
    }));

    ObservableList<Repository> items = createJavaFXThreadProxyList(model.getRepositories().sorted());

    repositories.setItems(items);
    EventStreams.sizeOf(items).subscribe(v -> total.setText(String.valueOf(v)));
    organization.textProperty().bindBidirectional(model.organizationProperty());
    bindBidirectional(limit.textProperty(), model.limitProperty(), new NumberStringConverter());
    loadButton.disableProperty().bind(Bindings.not(enabled));
    cancelButton.disableProperty().bind(Bindings.not(running));
    progress.visibleProperty().bind(running);

    Scene scene = new Scene(root);
    scene.getStylesheets().addAll(basename + ".css", "bootstrapfx.css");
    return scene;
}

From source file:com.rvantwisk.cnctools.controls.ToolParametersControl.java

public ToolParametersControl() {
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("ToolParameters.fxml"));
    fxmlLoader.setRoot(this);
    fxmlLoader.setController(this);
    try {//from  www . j  a va 2s  .com
        fxmlLoader.load();
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    }
}

From source file:com.fxexperience.previewer.controller.PreviewController.java

public PreviewController() {
    try {// w ww. j  a va 2  s  .c  om
        final FXMLLoader loader = new FXMLLoader();
        loader.setLocation(PreviewController.class.getResource("/fxml/FXMLPreviewPanel.fxml")); //NOI18N
        loader.setController(PreviewController.this);
        loader.setRoot(PreviewController.this);
        loader.load();

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

    choiceBox.getSelectionModel().select(0);
    comboBox.getSelectionModel().select(0);

    listView.setItems(FXCollections.observableArrayList("Alpha", "Beta", "Gamma"));
    //           System.out.println(this.getUserAgentStylesheet());
}

From source file:analyzer.code.FXMLAnalyzerController.java

@FXML
private void settingMunuItem() throws FileNotFoundException, IOException {
    FXMLLoader loader = new FXMLLoader(getClass().getResource("FXMLSetting.fxml"));
    try {//  w  w w .j a  va  2s  . c  o m
        AnchorPane pane = (AnchorPane) loader.load();
        fxmlsc = loader.getController();
        fxmlsc.setAnalyzer(this);
        Scene scene = new Scene(pane);
        Stage stage = new Stage();
        stage.setScene(scene);
        stage.setTitle("??");
        stage.show();
    } catch (Exception e) {
        e.printStackTrace();
    }
}