Java Code Examples for javafx.fxml.FXMLLoader#setBuilderFactory()

The following examples show how to use javafx.fxml.FXMLLoader#setBuilderFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GameView.java    From CrazyAlpha with GNU General Public License v2.0 6 votes vote down vote up
public static Initializable getInitializable(String viewName) throws IOException {
    FXMLLoader loader = new FXMLLoader();    // 创建对象

    loader.setBuilderFactory(new JavaFXBuilderFactory());    // 设置BuilderFactory
    loader.setLocation(GameView.class.getResource(viewName + ".fxml"));    // 设置路径基准

    try {
        InputStream in = GameView.class.getResourceAsStream(viewName + ".fxml");
        AnchorPane page = (AnchorPane) loader.load(in); // 对象方法的参数是InputStream,返回值是Object

        Scene scene = new Scene(page, 800, 600);
        Stage stage = new Stage();
        stage.setScene(scene);
        stage.sizeToScene();

        return (Initializable) loader.getController();    // 可以得到Controller

    } finally {
        in.close();
        return null;
    }
}
 
Example 2
Source File: UpdateController.java    From updatefx with MIT License 6 votes vote down vote up
public static void performUpdate(Release release, URL css) {
	try {
		ResourceBundle i18nBundle = ResourceBundle.getBundle("com.briksoftware.updatefx.gui.i18n.UpdateProgressDialog");

		FXMLLoader loader = new FXMLLoader(UpdateController.class.getResource("UpdateProgressDialog.fxml"), i18nBundle);
		loader.setBuilderFactory(new JavaFXBuilderFactory());
		Parent page = loader.load();
		UpdateController controller = loader.getController();
		controller.release = release;
		controller.initialize();

		Scene scene = new Scene(page);
		if (css != null) {
			scene.getStylesheets().add(css.toExternalForm());
		}
		
		final Stage stage = new Stage();
		stage.setScene(scene);
		stage.show();
		stage.toFront();

	} catch (Throwable ex) {
		ex.printStackTrace();
	}
}
 
Example 3
Source File: Designer.java    From pmd-designer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void start(Stage stage, DesignerRoot owner) throws IOException {
    this.designerRoot = owner;

    stage.setTitle("PMD Rule Designer (v " + Designer.VERSION + ')');
    setIcons(stage);

    Logger.getLogger(Attribute.class.getName()).setLevel(Level.OFF);

    System.out.println(stage.getTitle() + " initializing... ");

    FXMLLoader loader = new FXMLLoader(DesignerUtil.getFxml("designer"));

    MainDesignerController mainController = new MainDesignerController(owner);

    loader.setBuilderFactory(DesignerUtil.customBuilderFactory(owner));

    loader.setControllerFactory(DesignerUtil.controllerFactoryKnowing(
        mainController,
        new MetricPaneController(owner),
        new ScopesPanelController(owner),
        new NodeDetailPaneController(owner),
        new RuleEditorsController(owner),
        new SourceEditorController(owner)
    ));

    stage.setOnCloseRequest(e -> {
        owner.getService(DesignerRoot.PERSISTENCE_MANAGER).persistSettings(mainController);
        Platform.exit();
        // VM sometimes fails to exit for no apparent reason
        // all our threads are killed so it's not our fault
        System.exit(0);
    });

    Parent root = loader.load();
    Scene scene = new Scene(root);

    stage.setScene(scene);

    stage.show();

    if (!owner.isDeveloperMode()) {
        // only close after initialization succeeded.
        // so that fatal errors thrown by stage.show are not hidden
        System.err.close();
    }


    long initTime = System.currentTimeMillis() - initStartTimeMillis;

    System.out.println("done in " + initTime + "ms.");
    if (!owner.isDeveloperMode()) {
        System.out.println("Run with --verbose parameter to enable error output.");
    }
}
 
Example 4
Source File: StageBuilder.java    From pmd-designer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public StageBuilder withFxml(URL fxmlUrl, @NonNull DesignerRoot root, Object... controllers) {
    FXMLLoader loader = new FXMLLoader(fxmlUrl);
    loader.setBuilderFactory(customBuilderFactory(root));
    loader.setControllerFactory(controllerFactoryKnowing(controllers));
    Parent parent;
    try {
        parent = loader.load();
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    return withSceneRoot(parent);
}
 
Example 5
Source File: UpdateDialogController.java    From updatefx with MIT License 5 votes vote down vote up
public static void showUpdateDialog(Release release, int currentReleaseID, String currentVersion, int currentLicenseVersion, URL css) {
	try {
		ResourceBundle i18nBundle = ResourceBundle.getBundle("com.briksoftware.updatefx.gui.i18n.UpdateDialog");
		
		FXMLLoader loader = new FXMLLoader(UpdateDialogController.class.getResource("UpdateDialog.fxml"), i18nBundle);
		loader.setBuilderFactory(new JavaFXBuilderFactory());
		Parent page = loader.load();
		UpdateDialogController controller = loader.getController();
		controller.release = release;
		controller.currentReleaseID = currentReleaseID;
		controller.currentVersion = currentVersion;
		controller.currentLicenseVersion = currentLicenseVersion;
		controller.css = css;
		controller.initialize();
		
		Scene scene = new Scene(page);
		if (css != null) {
			scene.getStylesheets().add(css.toExternalForm());
		}
		
		final Stage stage = new Stage();
		stage.setScene(scene);
		stage.show();
		stage.toFront();
		
	} catch (Throwable ex) {
		ex.printStackTrace();
	}		
}