Java Code Examples for javafx.fxml.FXMLLoader

The following examples show how to use javafx.fxml.FXMLLoader. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public void start(Stage stage) throws IOException {

  // set up the scene
  FXMLLoader loader = new FXMLLoader(getClass().getResource("/orbit_the_camera_around_an_object/main.fxml"));
  Parent root = loader.load();
  controller = loader.getController();
  Scene scene = new Scene(root);

  // set up the stage
  stage.setTitle("Orbit the Camera Around an Object Sample");
  stage.setWidth(800);
  stage.setHeight(700);
  stage.setScene(scene);
  stage.show();
}
 
Example 2
Source Project: OpenLabeler   Source File: OpenLabeler.java    License: Apache License 2.0 6 votes vote down vote up
public static Stage createAboutStage(ResourceBundle bundle) {
    try {
        FXMLLoader loader = new FXMLLoader(OpenLabeler.class.getResource("/fxml/AboutPane.fxml"), bundle);
        Parent root = loader.load();

        Stage stage = new Stage();
        stage.setTitle(bundle.getString("app.name"));
        stage.focusedProperty().addListener((observable, oldValue, newValue) -> {
            if (!newValue) {
                stage.close();
            }
        });
        stage.initStyle(StageStyle.UNDECORATED);
        stage.setResizable(false);
        stage.setScene(new Scene(root));
        return stage;
    }
    catch (Exception ex) {
        LOG.log(Level.WARNING, "Failed to load ICNS file", ex);
    }

    return null;
}
 
Example 3
Source Project: archivo   Source File: Archivo.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void initRecordingList() {
    assert (rootController != null);

    try {
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(Archivo.class.getResource("view/RecordingList.fxml"));

        recordingListController = new RecordingListController(this);
        loader.setController(recordingListController);

        Pane recordingList = loader.load();
        rootController.getMainGrid().add(recordingList, 0, 0);
        rootController.setMenuBindings(recordingListController);

        recordingListController.startTivoSearch();
    } catch (IOException e) {
        logger.error("Error initializing recording list: ", e);
    }
}
 
Example 4
Source Project: MusicPlayer   Source File: PlayingTableCell.java    License: MIT License 6 votes vote down vote up
@Override
protected void updateItem(T item, boolean empty) {
	super.updateItem(item, empty);
	if (empty || item == null || !(Boolean) item) {
		setText(null);
		setGraphic(null);
	} else {
		try {
			String fileName = Resources.FXML + "PlayingIcon.fxml";
               FXMLLoader loader = new FXMLLoader(this.getClass().getResource(fileName));
               Pane pane = loader.load();
               setGraphic(pane);
           } catch (Exception ex) {
               ex.printStackTrace();
           }
	}
}
 
Example 5
Source Project: DevToolBox   Source File: Loading.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
    long time = System.currentTimeMillis();
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/loading.fxml"));
    Parent root = fxmlLoader.load();
    Scene scene = new Scene(root);
    stage.initStyle(StageStyle.UNDECORATED);
    stage.setAlwaysOnTop(true);
    stage.setScene(scene);
    stage.setTitle("启动中");
    stage.getIcons().add(new Image(getClass().getResourceAsStream("/skin/icon.png")));
    stage.show();
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
    System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");
    LoadingController lc = fxmlLoader.getController();
    ApplicationStageManager.putStageAndController(ApplicationStageManager.StateAndController.LOADING, stage, lc);
    ApplicationStageManager.setApplication(this);
    LOGGER.info("启动页加载耗时:" + (System.currentTimeMillis() - time) + "毫秒");
    new Thread(() -> {
        Platform.runLater(() -> {
            startMainApp(stage);
        });
    }).start();
}
 
Example 6
Source Project: MyBox   Source File: WebBrowserController.java    License: Apache License 2.0 6 votes vote down vote up
@FXML
protected void manageHistories() {
    try {
        FXMLLoader fxmlLoader = new FXMLLoader(FxmlStage.class.getResource(
                CommonValues.WebBrowserHistoryFxml), AppVariables.currentBundle);
        Pane pane = fxmlLoader.load();
        Tab tab = new Tab(message("ManageHistories"));
        ImageView tabImage = new ImageView("img/MyBox.png");
        tabImage.setFitWidth(20);
        tabImage.setFitHeight(20);
        tab.setGraphic(tabImage);
        tab.setContent(pane);
        tabPane.getTabs().add(tab);
        tabPane.getSelectionModel().select(tab);

        WebBrowserHistoryController controller = (WebBrowserHistoryController) fxmlLoader.getController();
        controller.parent = this;

    } catch (Exception e) {
        logger.error(e.toString());
    }
}
 
Example 7
private Stage createStage(Stage mainStage) {
    FXMLLoader loader = new FXMLLoader(DesignerUtil.getFxml("event-log"));
    loader.setController(this);

    final Stage dialog = new Stage();
    dialog.initOwner(mainStage.getScene().getWindow());
    dialog.initModality(Modality.NONE);

    Parent root;
    try {
        root = loader.load();
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }

    Scene scene = new Scene(root);
    dialog.setScene(scene);
    return dialog;
}
 
Example 8
Source Project: ApkToolPlus   Source File: ViewUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 打开一个新窗口
 *
 * @param fxmlUrl       fxml文件的url
 * @param isShowTitle   是否显示title
 * @return  Stage,如果出现异常返回null
 */
public static Stage newWindow(URL fxmlUrl, boolean isShowTitle){
    try {
        Stage stage = new Stage();
        if (!isShowTitle){
            setNoBroder(stage);
        }
        // 背景透明
        stage.initStyle(StageStyle.TRANSPARENT);
        Parent layout = FXMLLoader.load(fxmlUrl);

        Scene scene = new Scene(layout, Color.TRANSPARENT);
        stage.setScene(scene);

        // 在屏幕中间
        stage.centerOnScreen();

        return stage;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 9
@Override
public void start(Stage stage) throws Exception {

  // set up the scene
  FXMLLoader loader = new FXMLLoader(getClass().getResource("/trace_a_utility_network/main.fxml"));
  Parent root = loader.load();
  controller = loader.getController();
  Scene scene = new Scene(root);

  // set title, size and add scene to stage
  stage.setTitle("Trace a Utility Network Sample");
  stage.setWidth(800);
  stage.setHeight(700);
  stage.setScene(scene);
  stage.show();
}
 
Example 10
Source Project: tcMenu   Source File: MenuControllerApp.java    License: Apache License 2.0 6 votes vote down vote up
private RemoteMenuController showConfigChooser(MenuTree tree) throws Exception {
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/remoteSelector.fxml"));
    BorderPane pane = loader.load();
    RemoteSelectorController controller = loader.getController();
    controller.init(tree);

    Stage dialogStage = new Stage();
    dialogStage.getIcons().add(new Image(getClass().getResourceAsStream("/controller-icon.png")));
    dialogStage.setTitle("Connect to tcMenu device");
    dialogStage.initModality(Modality.WINDOW_MODAL);
    dialogStage.initOwner(null);
    Scene scene = new Scene(pane);
    dialogStage.setScene(scene);
    dialogStage.showAndWait();
    return controller.getResult();
}
 
Example 11
@FXML
private void changePasswordAction(ActionEvent event)
{
    mainTopAnchorPane.setEffect(new BoxBlur());
    passwordStage = new Stage();
    passwordStage.setOnCloseRequest(new EventHandler<WindowEvent>()
    {
        @Override
        public void handle(WindowEvent t)
        {
            mainTopAnchorPane.effectProperty().setValue(null);
        }
    });
    passwordStage.setTitle("Change Password");
    passwordStage.initModality(Modality.APPLICATION_MODAL);
    passwordStage.initStyle(StageStyle.UTILITY);
    passwordStage.setResizable(false);
    try
    {
        Parent passwordParent = FXMLLoader.load(getClass().getResource("changepassword.fxml"));
        passwordStage.setScene(new Scene(passwordParent));
        passwordStage.show();
    } catch (IOException ex)
    {
    }
}
 
Example 12
Source Project: curly   Source File: CurlyApp.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
    applicationWindow = stage;
    Locale locale = Locale.US;
    ApplicationState.getInstance().setResourceBundle(ResourceBundle.getBundle("Bundle", locale));
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/App.fxml"));
    loader.setResources(ApplicationState.getInstance().getResourceBundle());
    loader.load();
    Parent root = loader.getRoot();
    appController = loader.getController();

    Scene scene = new Scene(root);
    scene.getStylesheets().add("/styles/Styles.css");

    stage.setTitle(ApplicationState.getInstance().getResourceBundle().getString(APPLICATION_TITLE));
    stage.setScene(scene);
    stage.show();

    stage.setOnCloseRequest(event -> {
        ConnectionManager.getInstance().shutdown();
        Platform.exit();
        System.exit(0);
    });
}
 
Example 13
Source Project: xltsearch   Source File: MessageDisplay.java    License: Apache License 2.0 6 votes vote down vote up
MessageDisplay() {
    stage.setTitle("Messages");
    stage.getIcons().addAll(new Image(getClass().getResourceAsStream("/icon32.png")),
                            new Image(getClass().getResourceAsStream("/icon22.png")),
                            new Image(getClass().getResourceAsStream("/icon16.png")));
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/message_display.fxml"));
    fxmlLoader.setController(this);
    try {
        Scene scene = new Scene(fxmlLoader.load(), SCENE_WIDTH, SCENE_HEIGHT);
        stage.setScene(scene);
    } catch (Exception ex) {
        DetailedAlert alert = new DetailedAlert(DetailedAlert.AlertType.ERROR);
        alert.setTitle("Error");
        alert.setHeaderText("Exception while loading MessageDisplay");
        alert.setDetailsText(MessageLogger.getStackTrace(ex));
        alert.showAndWait();
    }
}
 
Example 14
Source Project: Path-of-Leveling   Source File: AddGem_Controller.java    License: MIT License 6 votes vote down vote up
private void fillBox(int whichAct, VBox whichActBox, HashMap<Zone, ArrayList<Gem>> gemHash, ArrayList<Zone> zoneList) {

        for(Zone z : zoneList){
            try {
                FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("questSplitPanel.fxml"));
                AnchorPane con = fxmlLoader.load();

                QuestSplitPanel_Controller controller = fxmlLoader.getController();
                whichActBox.getChildren().add(con);
                controller.load(z, gemHash.get(z), this);
                tablinkers.add(new TabLinker(controller,z, whichAct - 1));
                gemHash.get(z).forEach(gem -> m_gemNames.add(gem.getGemName()));
            } catch (IOException ex) {
                Logger.getLogger(QuestSplitPanel_Controller.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
            }

        }
    }
 
Example 15
Source Project: devcoretalk   Source File: Main.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** Loads the FXML file with the given name, blurs out the main UI and puts this one on top. */
public <T> OverlayUI<T> overlayUI(String name) {
    try {
        checkGuiThread();
        // Load the UI from disk.
        URL location = GuiUtils.getResource(name);
        FXMLLoader loader = new FXMLLoader(location);
        Pane ui = loader.load();
        T controller = loader.getController();
        OverlayUI<T> pair = new OverlayUI<T>(ui, controller);
        // Auto-magically set the overlayUI member, if it's there.
        try {
            if (controller != null)
                controller.getClass().getField("overlayUI").set(controller, pair);
        } catch (IllegalAccessException | NoSuchFieldException ignored) {
            ignored.printStackTrace();
        }
        pair.show();
        return pair;
    } catch (IOException e) {
        throw new RuntimeException(e);  // Can't happen.
    }
}
 
Example 16
Source Project: metastone   Source File: PlayModeView.java    License: GNU General Public License v2.0 6 votes vote down vote up
public PlayModeView() {
	FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/PlayModeView.fxml"));
	fxmlLoader.setRoot(this);
	fxmlLoader.setController(this);

	try {
		fxmlLoader.load();
	} catch (IOException exception) {
		throw new RuntimeException(exception);
	}

	boardView = new GameBoardView();
	// setCenter(boardView);
	loadingView = new LoadingBoardView();
	setCenter(loadingView);

	actionPromptView = new HumanActionPromptView();
	//sidePane.getChildren().add(actionPromptView);

	backButton.setOnAction(actionEvent -> NotificationProxy.sendNotification(GameNotification.MAIN_MENU));

	sidePane.getChildren().setAll(actionPromptView, navigationPane);
}
 
Example 17
Source Project: BlockMap   Source File: AboutDialog.java    License: MIT License 6 votes vote down vote up
public AboutDialog() throws IOException {
	super(AlertType.NONE, null, ButtonType.CLOSE);
	setTitle("About BlockMap");
	setResizable(true);
	initModality(Modality.APPLICATION_MODAL);

	FXMLLoader loader = new FXMLLoader(getClass().getResource("aboutpane.fxml"));
	loader.setController(this);
	getDialogPane().setContent(loader.load());
	getDialogPane().getStylesheets().add("/de/piegames/blockmap/gui/standalone/about/style.css");

	aboutTitle.setText("BlockMap " + VersionProvider.VERSION);

	@SuppressWarnings("serial")
	List<Dependency> dependencies = new GsonBuilder().registerTypeAdapterFactory(new GsonJava8TypeAdapterFactory()).create().fromJson(
			// TODO automate copying that file on dependency change
			new InputStreamReader(getClass().getResourceAsStream("licenseReport.json")),
			new TypeToken<List<Dependency>>() {
			}.getType());

	for (Dependency dependency : dependencies) {
		this.dependencies.getChildren().add(new DependencyPane(dependency));
	}

	license.setText(LICENSE_TEXT);
}
 
Example 18
Source Project: java_fx_node_link_demo   Source File: RootLayout.java    License: The Unlicense 6 votes vote down vote up
public RootLayout() {
	
	FXMLLoader fxmlLoader = new FXMLLoader(
			getClass().getResource("/RootLayout.fxml")
			);
	
	fxmlLoader.setRoot(this); 
	fxmlLoader.setController(this);
	
	try { 
		fxmlLoader.load();
       
	} catch (IOException exception) {
	    throw new RuntimeException(exception);
	}
}
 
Example 19
@Override
public void start(Stage stage) throws IOException {

  // set up the scene
  FXMLLoader loader = new FXMLLoader(getClass().getResource("/sketch_on_map/main.fxml"));
  Parent root = loader.load();
  controller = loader.getController();
  Scene scene = new Scene(root);

  // set up the stage
  stage.setTitle("Sketch on Map Sample");
  stage.setWidth(1000);
  stage.setHeight(700);
  stage.setScene(scene);
  stage.show();
}
 
Example 20
Source Project: PeerWasp   Source File: CustomizedTreeCell.java    License: MIT License 5 votes vote down vote up
private void showProperties(PathItem item) {
	try {
		FXMLLoader loader = new FXMLLoader();
		loader.setLocation(getClass().getResource(ViewNames.PROPERTIES_VIEW));
		loader.setController(new Properties(getItem()));

		Parent root = loader.load();

		// load UI on Application thread and show window
		Runnable showStage = new Runnable() {
			@Override
			public void run() {
				Scene scene = new Scene(root);
				stage = new Stage();
				stage.setTitle("Properties of "
						+ getItem().getPath().getFileName());
				stage.setScene(scene);
				stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
					@Override
					public void handle(WindowEvent event) {
						stage = null;
					}
				});

				stage.show();
			}
		};

		if (Platform.isFxApplicationThread()) {
			showStage.run();
		} else {
			Platform.runLater(showStage);
		}
	} catch (IOException e) {
		logger.warn("Exception while showing properties.", e);
	}
}
 
Example 21
Source Project: dctb-utfpr-2018-1   Source File: IndexController.java    License: Apache License 2.0 5 votes vote down vote up
public void callDefault(){
    try {
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(getClass().getClassLoader().getResource("pokedex/view/Default.fxml"));
        dynamic.getChildren().clear();
        dynamic.getChildren().add((AnchorPane)loader.load());
        controller = null;
    } catch (IOException ex) {
        Logger.getLogger(IndexController.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 22
Source Project: examples-javafx-repos1   Source File: WoodlandMain.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {

	FXMLLoader fxmlLoader = new FXMLLoader(WoodlandMain.class.getResource("/fxml/Woodland.fxml"));
	
	Parent p = fxmlLoader.load();
	
	Scene scene = new Scene( p );
	scene.getStylesheets().add( "css/woodland.css" );
	
	primaryStage.setTitle("Woodland");
	primaryStage.setScene( scene );
	primaryStage.show();
}
 
Example 23
@FXML
void btnStaffReg(ActionEvent event) {
    try {
        AnchorPane studentMgmt = FXMLLoader.load(getClass().getResource(("/sms/view/fxml/RegisterStaff.fxml")));
        studentManagement.getChildren().setAll(studentMgmt);
    }catch(IOException e){
        System.out.println(e);
    }
}
 
Example 24
Source Project: JavaFX-Chat   Source File: LoginController.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void loginButtonAction() throws IOException {
    String hostname = hostnameTextfield.getText();
    int port = Integer.parseInt(portTextfield.getText());
    String username = usernameTextfield.getText();
    String picture = selectedPicture.getText();

    FXMLLoader fmxlLoader = new FXMLLoader(getClass().getResource("/views/ChatView.fxml"));
    Parent window = (Pane) fmxlLoader.load();
    con = fmxlLoader.<ChatController>getController();
    Listener listener = new Listener(hostname, port, username, picture, con);
    Thread x = new Thread(listener);
    x.start();
    this.scene = new Scene(window);
}
 
Example 25
Source Project: Path-of-Leveling   Source File: GemOverlay_Controller.java    License: MIT License 5 votes vote down vote up
public void socketGroupReplace(Gem add, Gem remove){
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/poe/level/fx/overlay/replace_socket_group_overlay.fxml"));
    AnchorPane ap = null;
    try {
        ap = loader.load();
    } catch (IOException ex) {
        Logger.getLogger(GemOverlay_Controller.class.getName()).log(Level.SEVERE, null, ex);
    }
    loader.<Replace_socket_group_overlay_Controller>getController().load(add,remove);
    gem_overlay_container.getChildren().add(ap);

}
 
Example 26
Source Project: uip-pc2   Source File: Main.java    License: MIT License 5 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception{
    Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
    primaryStage.setTitle("Hello World");
    primaryStage.setScene(new Scene(root, 300, 275));
    primaryStage.show();
}
 
Example 27
Source Project: WIFIProbe   Source File: UIManager.java    License: Apache License 2.0 5 votes vote down vote up
public Parent initialize(Stage stage) {
    rootStage  = stage;
    FXMLLoader loader = ResourceTools.getFxmlConfig(View.INDEX);
    try {
        Parent parent = loader.load();
        initMvc(loader);
        rootParent = parent;
        return parent;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 28
Source Project: samples   Source File: Main.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception{
    Parent root = FXMLLoader.load(getClass().getResource("hellofx.fxml"));
    primaryStage.setTitle("Hello World");
    primaryStage.setScene(new Scene(root));
    primaryStage.show();
}
 
Example 29
Source Project: Library-Assistant   Source File: BookListController.java    License: Apache License 2.0 5 votes vote down vote up
@FXML
private void handleBookEditOption(ActionEvent event) {
    //Fetch the selected row
    Book selectedForEdit = tableView.getSelectionModel().getSelectedItem();
    if (selectedForEdit == null) {
        AlertMaker.showErrorMessage("No book selected", "Please select a book for edit.");
        return;
    }
    try {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("/library/assistant/ui/addbook/add_book.fxml"));
        Parent parent = loader.load();

        BookAddController controller = (BookAddController) loader.getController();
        controller.inflateUI(selectedForEdit);

        Stage stage = new Stage(StageStyle.DECORATED);
        stage.setTitle("Edit Book");
        stage.setScene(new Scene(parent));
        stage.show();
        LibraryAssistantUtil.setStageIcon(stage);

        stage.setOnHiding((e) -> {
            handleRefresh(new ActionEvent());
        });

    } catch (IOException ex) {
        Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 30
@FXML
void Back(ActionEvent event) {
    try {
        AnchorPane studentMgmt = FXMLLoader.load(getClass().getResource(("/sms/view/fxml/StaffManagement.fxml")));
        root.getChildren().setAll(studentMgmt);
    }catch(IOException e){
        System.out.println(e);
    }
}