当前位置 : 主页 > 编程语言 > c++ >

javafx 以新窗口形式打开一个界面

来源:互联网 收集:自由互联 发布时间:2021-07-03
gistfile1.txt // opens a dialog to edit details for the specified person. If the user// clicks OK, the changes are saved into the provided person object and true// is returned.public boolean showPersonEditDialog(Person person) {FXMLLoader l
gistfile1.txt
// opens a dialog to edit details for the specified person. If the user
	// clicks OK, the changes are saved into the provided person object and true
	// is returned.
	public boolean showPersonEditDialog(Person person) {
		FXMLLoader loader = new FXMLLoader();
		loader.setLocation(MainApp.class.getResource("view/PersonEditDialog.fxml"));
		try {
			AnchorPane page = (AnchorPane) loader.load();

			// Create the dialog Stage.
			Stage dialogStage = new Stage();
			dialogStage.setTitle("Edit Person");
			dialogStage.initModality(Modality.WINDOW_MODAL);
			dialogStage.initOwner(primaryStage);
			Scene scene = new Scene(page);
			dialogStage.setScene(scene);

			// set the person into the controller
			PersonEditDialogController controller = loader.getController();
			controller.setDialogStage(dialogStage);
			controller.setPerson(person);

			// show the dialog and wait until the user closes it
			dialogStage.showAndWait();

			return controller.isOkClicked();
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
	}
网友评论