当前位置: 首页>>代码示例>>Java>>正文


Java FXMLLoader.setControllerFactory方法代码示例

本文整理汇总了Java中javafx.fxml.FXMLLoader.setControllerFactory方法的典型用法代码示例。如果您正苦于以下问题:Java FXMLLoader.setControllerFactory方法的具体用法?Java FXMLLoader.setControllerFactory怎么用?Java FXMLLoader.setControllerFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javafx.fxml.FXMLLoader的用法示例。


在下文中一共展示了FXMLLoader.setControllerFactory方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import javafx.fxml.FXMLLoader; //导入方法依赖的package包/类
@Override
public void start(Stage primaryStage) throws IOException {
    primaryStage.addEventFilter(KeyEvent.KEY_PRESSED, this);
    this.primaryStage = primaryStage;
    primaryStage.setTitle("Blindfold");
    ClassLoader classLoader = getClass().getClassLoader();
    FXMLLoader fxmlLoader = new FXMLLoader(classLoader.getResource("fxml/Blindfold.fxml"));
    fxmlLoader.setControllerFactory((Class<?> param) -> {
        return this;
    });

    Parent root = (Parent) fxmlLoader.load();
    Scene scene = new Scene(root);
    primaryStage.setScene(scene);
    primaryStage.show();
}
 
开发者ID:miyagilabs,项目名称:Blindfold,代码行数:17,代码来源:Blindfold.java

示例2: start

import javafx.fxml.FXMLLoader; //导入方法依赖的package包/类
@Override
public void start(Stage primaryStage) throws IOException {
    Module module = new ETUmulatorModule();
    Injector injector = Guice.createInjector(module);

    primaryStage.setTitle("ETUmulator");
    ClassLoader classLoader = ETUmulator.class.getClassLoader();
    FXMLLoader fxmlLoader = new FXMLLoader(classLoader.getResource("fxml/ETUmulator.fxml"));
    fxmlLoader.setControllerFactory(injector::getInstance);
    Parent root = (Parent) fxmlLoader.load();
    Scene scene = new Scene(root);
    primaryStage.setScene(scene);
    primaryStage.show();

    injector.injectMembers(this);
    fileMenuController.setWindow(primaryStage.getOwner());

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            processor.stop();
        }
    });
    primaryStage.setOnCloseRequest((event) -> {
        processor.terminate();
        primaryStage.close();
    });
}
 
开发者ID:kasirgalabs,项目名称:ETUmulator,代码行数:29,代码来源:ETUmulator.java

示例3: get

import javafx.fxml.FXMLLoader; //导入方法依赖的package包/类
/**
 * Create the view and controller associated with the provided FXML URL
 * 
 * @param url
 *            the location of the FXML file, relative to the
 *            {@code sic.nmsu.javafx} package
 * @param stateInit
 *            a consumer used to configure the controller before FXML injection
 * @return the initialized view and controller
 */
public static <C extends FXController> Pair<Parent, C> get(String url, Consumer<C> stateInit) {
	FXMLLoader loader = new FXMLLoader(App.class.getResource(url));
	loader.setControllerFactory(ctrlClass -> {
		@SuppressWarnings("unchecked")
		C ctrl = (C) Resolver.resolve(ctrlClass);
		if (stateInit != null)
			stateInit.accept(ctrl);
		return ctrl;
	});

	try {
		loader.load();
	} catch (IOException e) {
		logger.error(e.getMessage());
		e.printStackTrace();
		return null;
	}

	return new Pair<Parent, C>(loader.getRoot(), loader.getController());
}
 
开发者ID:NMSU-SIC-Club,项目名称:JavaFX_Tutorial,代码行数:31,代码来源:FXController.java

示例4: ModalDialog

import javafx.fxml.FXMLLoader; //导入方法依赖的package包/类
public ModalDialog(final Modal controller, URL fxml, Window owner, StageStyle style, Modality modality, ResourceBundle bundle) {
    super(style);
    initOwner(owner);
    initModality(modality);
    FXMLLoader loader = new FXMLLoader(fxml);
    loader.setResources(bundle);
    try {
        loader.setControllerFactory(new Callback<Class<?>, Object>() {
            public Object call(Class<?> aClass) {
                return controller;
            }
        });
        controller.setDialog(this);
        scene = new Scene((Parent) loader.load());
        setScene(scene);
    } catch (IOException e) {
        logger.error("Error loading modal class", e);
        throw new RuntimeException(e);
    }
}
 
开发者ID:stancalau,项目名称:springfx,代码行数:21,代码来源:ModalDialog.java

示例5: createFxmlLoader

import javafx.fxml.FXMLLoader; //导入方法依赖的package包/类
private FXMLLoader createFxmlLoader(String resource, ResourceBundle resourceBundle, View<?> codeBehind, Object root,
                                    ViewModel viewModel, ContextImpl context, ObservableBooleanValue viewInSceneProperty) throws IOException {
    // Load FXML file
    final URL location = FxmlViewLoader.class.getResource(resource);
    if (location == null) {
        throw new IOException("Error loading FXML - can't load from given resourcepath: " + resource);
    }

    final FXMLLoader fxmlLoader = new FXMLLoader();

    fxmlLoader.setRoot(root);
    fxmlLoader.setResources(resourceBundle);
    fxmlLoader.setLocation(location);

    // when the user provides a viewModel but no codeBehind, we need to use
    // the custom controller factory.
    // in all other cases the default factory can be used.
    if (viewModel != null && codeBehind == null) {
        fxmlLoader
                .setControllerFactory(new ControllerFactoryForCustomViewModel(viewModel, resourceBundle, context, viewInSceneProperty));
    } else {
        fxmlLoader.setControllerFactory(new DefaultControllerFactory(resourceBundle, context, viewInSceneProperty));
    }

    // When the user provides a codeBehind instance we take care of the
    // injection of the viewModel to this
    // controller here.
    if (codeBehind != null) {
        fxmlLoader.setController(codeBehind);

        if (viewModel == null) {
            handleInjection(codeBehind, resourceBundle, context, viewInSceneProperty);
        } else {
            handleInjection(codeBehind, resourceBundle, viewModel, context, viewInSceneProperty);
        }
    }

    return fxmlLoader;
}
 
开发者ID:cmlanche,项目名称:easyMvvmFx,代码行数:40,代码来源:FxmlViewLoader.java

示例6: constructRoot

import javafx.fxml.FXMLLoader; //导入方法依赖的package包/类
private void constructRoot() {
	FXMLLoader loader = new FXMLLoader(this.getClass().getResource(getResourcePath()));
	loader.setControllerFactory(type -> this);

	try {
		root = loader.load();
	}
	catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:GoSuji,项目名称:Suji,代码行数:12,代码来源:SelfBuildingController.java

示例7: start

import javafx.fxml.FXMLLoader; //导入方法依赖的package包/类
@Override
public void start(final Stage stage) throws Exception {

    this.com.start();
    this.consolePipe.open();
    this.processManager.start();

    stage.setTitle("Boutique-de-jus Bootstrap Control");
    stage.initStyle(StageStyle.DECORATED);

    FXMLLoader loader = new FXMLLoader(getClass().getResource("/main.fxml"));
    loader.setControllerFactory((c) -> {
        try {
            Object controller = c.newInstance();
            if (ProcessController.class.isAssignableFrom(c)) {
                ((ProcessController) controller).setup(this.com,
                                                       this.consolePipe,
                                                       this.scheduler,
                                                       this.processManager);
            }
            return controller;
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    });

    TabPane tabPane = loader.load();

    Scene scene = new Scene(tabPane, 1024, 768, Color.AQUA);
    scene.getStylesheets().add(getClass().getResource("/style.css").toExternalForm());
    stage.setScene(scene);
    stage.show();

    /*
    Notifications.create()
                 .title("Achievement unlocked")
                 .text("Bring up a Desktop Notification!")
                 .hideAfter(Duration.seconds(2))
                 .showWarning();
                 */
}
 
开发者ID:gmuecke,项目名称:boutique-de-jus,代码行数:42,代码来源:BoutiqueDeJusBootstrap.java

示例8: createFXMLController

import javafx.fxml.FXMLLoader; //导入方法依赖的package包/类
public static <T> T createFXMLController(Class<T> controllerClass, Callback<Class<?>, Object> controllerFactory) throws IOException {
	URL fxmlClasspathURL = createControllerFXMLClasspathURL(controllerClass);
	FXMLLoader fxmlLoader = new FXMLLoader(fxmlClasspathURL);
	fxmlLoader.setControllerFactory(controllerFactory);
	fxmlLoader.load();
	return fxmlLoader.getController();
}
 
开发者ID:Azzurite,项目名称:MinecraftServerSync,代码行数:8,代码来源:FXUtil.java

示例9: getNode

import javafx.fxml.FXMLLoader; //导入方法依赖的package包/类
private Node getNode(final Presentation control, URL location) {
    FXMLLoader loader = new FXMLLoader(location, lang.getBundle());
    loader.setControllerFactory(new Callback<Class<?>, Object>() {
        public Object call(Class<?> aClass) {
            return control;
        }
    });

    try {
        return (Node) loader.load();
    } catch (Exception e) {
        logger.error("Error casting node", e);
        return null;
    }
}
 
开发者ID:stancalau,项目名称:springfx,代码行数:16,代码来源:ScreensConfig.java


注:本文中的javafx.fxml.FXMLLoader.setControllerFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。