List of usage examples for javafx.fxml FXMLLoader load
public <T> T load() throws IOException
From source file:org.sleuthkit.autopsy.imageanalyzer.FXMLConstructor.java
static public void construct(Node n, String fxmlFileName) { final String name = "nbres:/" + StringUtils.replace(n.getClass().getPackage().getName(), ".", "/") + "/" + fxmlFileName;// w w w. j ava2s . c om // System.out.println(name); try { FXMLLoader fxmlLoader = new FXMLLoader(new URL(name)); fxmlLoader.setRoot(n); fxmlLoader.setController(n); try { fxmlLoader.load(); } catch (IOException exception) { try { fxmlLoader.setClassLoader(FXMLLoader.getDefaultClassLoader()); fxmlLoader.load(); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); } }
From source file:org.sleuthkit.autopsy.timeline.FXMLConstructor.java
static public void construct(Node n, String fxmlFileName) { final String name = "nbres:/" + StringUtils.replace(n.getClass().getPackage().getName(), ".", "/") + "/" + fxmlFileName; // NON-NLS System.out.println(name);/*from w ww. j a va 2s .c o m*/ try { FXMLLoader fxmlLoader = new FXMLLoader(new URL(name)); fxmlLoader.setRoot(n); fxmlLoader.setController(n); try { fxmlLoader.load(); } catch (IOException exception) { try { fxmlLoader.setClassLoader(FXMLLoader.getDefaultClassLoader()); fxmlLoader.load(); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); } }
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. */// ww w . ja va 2s . 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:jlotoprint.MainViewController.java
public static Stage loadTemplateChooser() { final Stage stage = new Stage(); try {/*from ww w . j a v a2 s. co m*/ FXMLLoader dialog = new FXMLLoader(MainViewController.class.getResource("TemplateDialog.fxml")); Parent root = (Parent) dialog.load(); root.addEventHandler(TemplateDialogEvent.CANCELED, (actionEvent) -> { stage.close(); }); stage.setScene(new Scene(root)); stage.setTitle("Choose a template"); stage.getIcons().add(new Image("file:resources/icon.png")); stage.initModality(Modality.WINDOW_MODAL); stage.initOwner(JLotoPrint.stage.getScene().getWindow()); stage.show(); } catch (IOException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); return null; } return stage; }
From source file:com.ggvaidya.scinames.tabulardata.TabularDataViewController.java
public static TabularDataViewController createTabularDataView() { Scene scene;//from w w w . ja 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 av a2 s. 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:spdxedit.PackageEditor.java
/** * Opens the modal package editor for the provided package. * * @param pkg The package to edit. * @param relatablePackages Packages to which the edited package may optionally have defined relationships * @param parentWindow The parent window. */// ww w. j av a 2 s.com public static void editPackage(final SpdxPackage pkg, final List<SpdxPackage> relatablePackages, SpdxDocumentContainer documentContainer, Window parentWindow) { final PackageEditor packageEditor = new PackageEditor(pkg, relatablePackages, documentContainer); final Stage dialogStage = new Stage(); dialogStage.setTitle("Edit SPDX Package: " + pkg.getName()); dialogStage.initStyle(StageStyle.DECORATED); dialogStage.initModality(Modality.APPLICATION_MODAL); dialogStage.setY(parentWindow.getX() + parentWindow.getWidth() / 2); dialogStage.setY(parentWindow.getY() + parentWindow.getHeight() / 2); dialogStage.setResizable(false); try { FXMLLoader loader = new FXMLLoader(NewPackageDialog.class.getResource("/PackageEditor.fxml")); loader.setController(packageEditor); Pane pane = loader.load(); Scene scene = new Scene(pane); dialogStage.setScene(scene); dialogStage.getIcons().clear(); dialogStage.getIcons().add(UiUtils.ICON_IMAGE_VIEW.getImage()); //Populate the file list on appearance dialogStage.setOnShown(event -> { try { final SpdxFile dummyfile = new SpdxFile(pkg.getName(), null, null, null, null, null, null, null, null, null, null, null, null); TreeItem<SpdxFile> root = new TreeItem<>(dummyfile); packageEditor.filesTable.setRoot(root); //Assume a package without is external //TODO: replace with external packages or whatever alternate mechanism in 2.1 packageEditor.btnAddFile.setDisable(pkg.getFiles().length == 0); root.getChildren() .setAll(Stream.of(pkg.getFiles()) .sorted(Comparator.comparing(file -> StringUtils.lowerCase(file.getName()))) //Sort by file name .map(TreeItem<SpdxFile>::new).collect(Collectors.toList())); } catch (InvalidSPDXAnalysisException e) { logger.error("Unable to get files for package " + pkg.getName(), e); } packageEditor.tabFiles.setExpanded(true); }); //Won't assign this event through FXML - don't want to propagate the stage beyond this point. packageEditor.btnOk.setOnMouseClicked(event -> dialogStage.close()); dialogStage.showAndWait(); } catch (IOException ioe) { throw new RuntimeException("Unable to load dialog", ioe); } }
From source file:org.sandsoft.acefx.AceEditor.java
/** * Creates a new instance of the ace editor. * * @return//from w w w . j a v a 2 s.com * @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:com.ggvaidya.scinames.complexquery.ComplexQueryViewController.java
public static ComplexQueryViewController createComplexQueryView(ProjectView pv) { Scene scene;/*from w w w . ja v a 2 s. c om*/ 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:caillou.company.clonemanager.gui.spring.SpringFxmlLoader.java
public static LoadingMojo load(String url, final String controllerClassName) { lastLoadedURL = url;/*from w w w . j a v a2 s . c o m*/ 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; }