我有一个名为Principale.fxml的fxml文件,其中包含一个buton。 当我点击它时,打开另一个舞台,并将一个BoxBlur效果添加到principale.fxml中的AnchorPane。 所以当我关闭第二阶段时,我希望将此效果设置为null为此AnchorPane 这是我的代码:
principale.fxml
info.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
Parent home_page_p = FXMLLoader.load(getClass().getResource("/View/information.fxml"));
Scene home_page_s = new Scene (home_page_p);
javafx.scene.effect.BoxBlur bxb = new BoxBlur();
ancr.setEffect(bxb);
Stage stage = new Stage();
stage.initStyle(StageStyle.UNDECORATED);
stage.setScene(home_page_s);
stage.show();
} catch (IOException ex) {
Logger.getLogger(PrincipaleController.class.getName()).log(Level.SEVERE, null, ex);
}
当我执行时我得到了这个 http://i.stack.imgur.com/VAFqG.jpg
Information.fxml
public void closeApp(MouseEvent mv) throws IOException
{
app_stage = (Stage) close.getScene().getWindow();
app_stage.hide();
PrincipaleController pc = new PrincipaleController();
pc.ancr.setEffect(null);
}
http://i.stack.imgur.com/VAFqG.jpg
所以当我关闭信息窗口时我想将principale.fxml效果设置为null,我应该向closeapp方法添加什么?
答案 0 :(得分:0)
您的代码存在多个问题。你不应该输入
Controller ctl = new Controller();
使用
从FXMLLoader中获取它FXMLLoader loader = FXMLLoader.load(getClass().getResource("/View/information.fxml"));
Parent home_page_p = loader.load();
Controller ctl = loader.getController();
稍后使用它来创建一个新阶段:
Stage stage = new Stage();
stage.initStyle(StageStyle.UNDECORATED);
ctl.Glisse(home_page_p, stage, home_page_s);
stage.setScene(home_page_s);
// Adding a event handler to be fired on the event of stage being closed
stage.setOnCloseRequest((WindowEvent event) -> {
// Perform some action when the stage is closed
ancr.setEffect(null); // ancr is a reference to the anchorpane
}
注意:您不需要创建另一个PrincipaleController
实例,因为以上所有代码都是在PrincipaleController class
内编写的。