List of usage examples for javafx.fxml FXMLLoader getController
@SuppressWarnings("unchecked") public <T> T getController()
From source file:org.sandsoft.cymric.util.Commons.java
/** * Create a new custom pane from FXML data. <br> * Restraints: Name and package of FXML file should be the same as * <code>resourceClass</code>. <code>resourceClass</code> should extend * <code>BorderPane</code> or one of its descendents. * * @param resourceClass Pane class in which data to be loaded. * @return Pane type object containing loaded node. *//*from ww w .jav a2 s .c o m*/ public static Pane loadPaneFromFXML(Class resourceClass) throws IOException { //init loader FXMLLoader loader = new FXMLLoader(); loader.setLocation(resourceClass.getResource(resourceClass.getSimpleName() + ".fxml")); //load fxml Node node = (Node) loader.load(); BorderPane control = (BorderPane) loader.getController(); BorderPane.setAlignment(node, Pos.CENTER); control.setCenter(node); return control; }
From source file:cz.lbenda.gui.controls.TextAreaFrmController.java
/** Create new instance return main node and controller of this node and sub-nodes */ public static Tuple2<Parent, TextAreaFrmController> createNewInstance() { URL resource = TextAreaFrmController.class.getResource(FXML_RESOURCE); try {/*from ww w . j a v a2s. c o m*/ FXMLLoader loader = new FXMLLoader(); loader.setLocation(resource); loader.setBuilderFactory(new JavaFXBuilderFactory()); Parent node = loader.load(resource.openStream()); TextAreaFrmController controller = loader.getController(); return new Tuple2<>(node, controller); } catch (IOException e) { LOG.error("Problem with reading FXML", e); throw new RuntimeException("Problem with reading FXML", e); } }
From source file:cz.lbenda.dataman.db.frm.DbConfigFrmController.java
/** Create new instance return main node and controller of this node and sub-nodes */ public static Tuple2<Parent, DbConfigFrmController> createNewInstance() { URL resource = DbConfigFrmController.class.getResource(FXML_RESOURCE); try {/*from ww w.ja v a2s .c o m*/ FXMLLoader loader = new FXMLLoader(); loader.setLocation(resource); loader.setBuilderFactory(new JavaFXBuilderFactory()); Parent node = loader.load(resource.openStream()); DbConfigFrmController controller = loader.getController(); return new Tuple2<>(node, controller); } catch (IOException e) { LOG.error("Problem with reading FXML", e); throw new RuntimeException("Problem with reading FXML", e); } }
From source file:com.ggvaidya.scinames.tabulardata.TabularDataViewController.java
public static TabularDataViewController createTabularDataView() { Scene scene;/*from w ww.j a v a 2 s . c o m*/ FXMLLoader loader = new FXMLLoader( TabularDataViewController.class.getResource("/fxml/TabularDataView.fxml")); AnchorPane ap; try { ap = (AnchorPane) loader.load(); } catch (IOException e) { throw new RuntimeException("Could not load internal file 'TabularDataView.fxml': " + e); } scene = new Scene(ap); TabularDataViewController controller = loader.getController(); controller.setScene(scene); return controller; }
From source file:de.micromata.mgc.javafx.ControllerService.java
public static <T extends Node, C> Pair<T, C> loadScene(String path, Class<T> nodeClass, Class<C> controlerClass) { try (InputStream is = ControllerService.class.getResourceAsStream(path)) { if (is == null) { throw new IllegalArgumentException("Canot find fxml file: " + path); }/*w w w .j a v a 2s .c o m*/ } catch (IOException ex) { throw new IllegalArgumentException("Canot find fxml file: " + path); } ResourceBundle resbundle = I18NTranslations .asResourceBundle(MgcLauncher.get().getApplication().getTranslateService()); FXMLLoader fxmlLoader = new FXMLLoader(ControllerService.class.getResource(path), resbundle, null, clazz -> { if (clazz.isAssignableFrom(controlerClass) == true) { return PrivateBeanUtils.createInstance(controlerClass); } else { return PrivateBeanUtils.createInstance(clazz); } }); try { Object loaded = fxmlLoader.load(); Object controler = fxmlLoader.getController(); Validate.notNull(loaded); Validate.notNull(controler); return Pair.make((T) loaded, (C) controler); } catch (IOException ex) { throw new RuntimeIOException(ex); } }
From source file:org.sandsoft.acefx.AceEditor.java
/** * Creates a new instance of the ace editor. * * @return/*from www. j a v a 2 s. c om*/ * @throws java.io.IOException */ public static AceEditor createNew() throws IOException { //init loader FXMLLoader loader = new FXMLLoader(); loader.setLocation(AceEditor.class.getResource(AceEditor.class.getSimpleName() + ".fxml")); //attach node Node node = (Node) loader.load(); BorderPane.setAlignment(node, Pos.CENTER); AceEditor ace = (AceEditor) loader.getController(); ace.setCenter(node); ace.setMinSize(0, 0); ace.setPrefSize(600, 400); ace.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE); //post load work ace.initialize(); return ace; }
From source file:caillou.company.clonemanager.gui.spring.SpringFxmlLoader.java
public static LoadingMojo load(String url, final String controllerClassName) { lastLoadedURL = url;/* ww w . java 2 s.c om*/ FXMLLoader loader = new FXMLLoader(MainApp.class.getResource(url), resourceBundle); loader.setControllerFactory(new Callback<Class<?>, Object>() { @Override public Object call(Class<?> clazz) { if (controllerClassName != null) { try { return applicationContext.getBean(Class.forName(controllerClassName)); } catch (ClassNotFoundException ex) { Logger.getLogger(SpringFxmlLoader.class.getName()).log(Level.SEVERE, null, ex); } } return applicationContext.getBean(clazz); } }); try { Parent parent = loader.load(); LoadingMojo loadingMojo = new LoadingMojo(); loadingMojo.setController(loader.getController()); loadingMojo.setParent(parent); return loadingMojo; } catch (IOException ex) { Logger.getLogger(SpringFxmlLoader.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception exMain) { System.out.println("Error"); } return null; }
From source file:com.ggvaidya.scinames.complexquery.ComplexQueryViewController.java
public static ComplexQueryViewController createComplexQueryView(ProjectView pv) { Scene scene;//from w ww . ja v a 2 s. c o m FXMLLoader loader = new FXMLLoader( TabularDataViewController.class.getResource("/fxml/ComplexQueryView.fxml")); AnchorPane ap; try { ap = (AnchorPane) loader.load(); } catch (IOException e) { throw new RuntimeException("Could not load internal file 'ComplexQueryView.fxml': " + e); } scene = new Scene(ap); ComplexQueryViewController controller = loader.getController(); controller.scene = scene; controller.projectView = pv; return controller; }
From source file:gov.va.isaac.gui.preferences.plugins.ViewCoordinatePreferencesPluginViewController.java
protected static ViewCoordinatePreferencesPluginViewController construct() throws IOException { // Load from FXML. URL resource = ViewCoordinatePreferencesPluginViewController.class .getResource("ViewCoordinatePreferencesPluginView.fxml"); log.debug("Loaded URL {}", resource); FXMLLoader loader = new FXMLLoader(resource); loader.load();//from w ww. ja v a 2s. com return loader.getController(); }
From source file:com.github.tddts.jet.view.fx.spring.DialogProvider.java
private <T extends Dialog<?>> T getDialogWithContent(FxDialog dialogAnnotation) { FXMLLoader loader = loadDialogView(dialogAnnotation); T dialog = loader.getController(); setDialogContent(dialog, loader.getRoot(), dialogAnnotation); return dialog; }