本文整理汇总了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();
}
示例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();
});
}
示例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());
}
示例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);
}
}
示例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;
}
示例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();
}
}
示例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();
*/
}
示例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();
}
示例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;
}
}