How to apply a blur effect when a StageModal overlaps a Stage already opened in JavaFX

0

Well my doubt is as follows, I would like to apply an effect in which, when I open a new window, the window that was overlapped is blurred, I tried to use

public Stage stageModal(String controller, String titulo){
    try {
        AnchorPane root = new AnchorPane();
        root = FXMLLoader.load(getClass().getResource("/com/ProcessosJuridicos/view/"+controller+".fxml"));
        root.setStyle("-fx-background-color: black");
        Scene scene = new Scene(root);
        final Stage stage = new Stage();
        stage.setScene(scene);
        stage.setTitle(titulo);
        GaussianBlur blur = new GaussianBlur(55);
        ColorAdjust adj = new ColorAdjust(0, -0.9, -0.5, 0);
        adj.setInput(blur);
        root.setEffect(adj);
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.show();
        return stage;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

The way I tried to do it applies the "effect" in the window in which it was opened

    
asked by anonymous 14.01.2018 / 06:03

1 answer

0

Try this way, as I believe you should take the owner of the open stage as modal and apply the effect;

GaussianBlur blur = new GaussianBlur(55);
final Stage stage = new Stage();
stage.getOwner().getScene().getRoot().setEffect(blur);

To remove the effect from the parent window when the modal is closed:

stage.setOnCloseRequest(event ->
   stage.getOwner().getScene().getRoot().setEffect(null)
);
    
22.01.2018 / 13:31