如何使用JavaFX创建并打开一个新窗口界面?
- 内容介绍
- 文章标签
- 相关推荐
本文共计176个文字,预计阅读时间需要1分钟。
打开指定人员的编辑详情对话框。如果用户点击确定,则更改将保存到提供的人员对象中,并返回true。 javapublic boolean openEditDialogForPerson(Person person) { FXMLLoader l=new FXMLLoader(); // ...}
// 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; } }
本文共计176个文字,预计阅读时间需要1分钟。
打开指定人员的编辑详情对话框。如果用户点击确定,则更改将保存到提供的人员对象中,并返回true。 javapublic boolean openEditDialogForPerson(Person person) { FXMLLoader l=new FXMLLoader(); // ...}
// 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; } }

