Example usage for javafx.fxml FXMLLoader setController

List of usage examples for javafx.fxml FXMLLoader setController

Introduction

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

Prototype

public void setController(Object controller) 

Source Link

Document

Sets the controller associated with the root object.

Usage

From source file:dev.archiecortez.jfacelog.dialogs.NewPassDialog.java

public NewPassDialog() throws IOException {
    super();/*w ww.  j  av a  2s . c  o  m*/
    FXMLLoader loader = new FXMLLoader(getClass().getResource("newpassdialog.fxml"));
    loader.setController(this);

    Parent root = loader.load();
    this.getDialogPane().setContent(root);
    getDialogPane().getButtonTypes().add(ButtonType.APPLY);
    getDialogPane().getButtonTypes().add(ButtonType.CANCEL);
    getDialogPane().lookupButton(ButtonType.APPLY).disableProperty()
            .bind(newPassword.textProperty().isNotEqualTo(newPasswordCopy.textProperty())
                    .or(newPassword.textProperty().isEmpty()).or(oldPassword.textProperty().isEmpty()));

    setResultConverter(value -> {
        if (value == ButtonType.APPLY) {
            return new Pair<>(oldPassword.getText(), newPassword.getText());
        } else {
            return null;
        }
    });
}

From source file:ninja.javafx.smartcsv.fx.FXMLController.java

protected final void loadFXML() throws IOException {
    try (InputStream fxmlStream = getClass().getResourceAsStream(fxmlFilePath)) {
        FXMLLoader loader = new FXMLLoader();
        loader.setResources(ResourceBundle.getBundle(this.resourcePath));
        loader.setController(this);
        this.view = (loader.load(fxmlStream));
    } catch (Throwable t) {
        t.printStackTrace();// ww w.  java2s.c om
    }
}

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

public BattleLobbyNode(FXMLLoaderFactory factory) throws IOException {
    URL resource = getClass().getResource("BattleLobbyNode.fxml");
    FXMLLoader loader = factory.get();
    loader.setLocation(resource);/*  www. j  a  va  2s.  co m*/
    loader.setRoot(this);
    loader.setController(this);
    loader.load();
}

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  www. ja 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:ninja.eivind.hotsreplayuploader.window.nodes.UploaderNode.java

@Autowired
public UploaderNode(FXMLLoaderFactory factory) throws IOException {
    super();/*  w  w  w.  ja  va  2 s . c o  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:com.esri.geoevent.test.performance.ui.ProducerUI.java

@Override
public void start(Stage primaryStage) {
    String modeStr = "Producer";
    if (StringUtils.isEmpty(modeStr)) {
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_NULL")
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();// w  w w .  j a v  a 2 s .c o m
        System.exit(0);
        return;
    }

    Mode mode = Mode.fromValue(modeStr);
    String fxmlFile = "";
    Object controller = null;
    switch (mode) {
    case Producer:
        fxmlFile = "PerformanceCollector.fxml";
        controller = new ProducerController();
        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);

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

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

@Override
public void start(Stage primaryStage) {

    String modeStr = "Consumer";
    if (StringUtils.isEmpty(modeStr)) {
        System.err.print(UIMessages.getMessage("STARTUP_ERROR_MODE_NULL")
                + UIMessages.getMessage("STARTUP_MODE_TYPES", Mode.getAllowableValues()));
        Platform.exit();//from w w w.  j a  v a 2s .c  om
        System.exit(0);
        return;
    }

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

    case Consumer:
        fxmlFile = "PerformanceCollector.fxml";
        controller = new ConsumerController();
        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);

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

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 . co 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.fxexperience.previewer.controller.PreviewController.java

public PreviewController() {
    try {/*from  w ww  .j ava 2 s  .co m*/
        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:io.github.mzmine.util.jfreechart.ManualZoomDialog.java

/**
 * Constructor//from  w w w. jav a  2s .com
 */
public ManualZoomDialog(Window parent, XYPlot plot) {

    initOwner(parent);

    setTitle("Manual zoom");

    setGraphic(new ImageView("file:icons/axesicon.png"));

    getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);

    xAxis = (NumberAxis) plot.getDomainAxis();
    yAxis = (NumberAxis) plot.getRangeAxis();

    try {
        URL layersDialogFXML = getClass().getResource(DIALOG_FXML);
        FXMLLoader loader = new FXMLLoader(layersDialogFXML);
        loader.setController(this);
        GridPane grid = loader.load();
        getDialogPane().setContent(grid);
    } catch (Exception e) {
        e.printStackTrace();
    }

    final Button btOk = (Button) getDialogPane().lookupButton(ButtonType.OK);
    btOk.addEventFilter(ActionEvent.ACTION, event -> {
        commitChanges(event);
    });

}