Domanda

I want to bring a fade effect when a new window appears. Also nothing should be possible without closing the window. My code to open the new window when a button is pressed in given below :

    Button b4 = new Button("ABOUT");
    b4.setFont(Font.font("Calibri", FontWeight.BOLD, 17));
    b4.setPrefSize(100, 30);
    b4.setStyle(" -fx-base: #ffffff;");
    b4.setTextFill(Color.BLACK);

    b4.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent e) {
            Stage usrpagestage = new Stage();
            usrpagestage.setMaxHeight(160);
            usrpagestage.setMaxWidth(210);
            usrpagestage.setResizable(false);
            usrpagestage.initStyle(StageStyle.UTILITY);
            usrpagestage.setScene(new Scene(new About()));
            usrpagestage.show();
        }
    });

The current look of my 2 windows is given below. I only want to make visible the small window and the rest should appear as faded. How can I do it ?

enter image description here

È stato utile?

Soluzione

try this..

       b4.setOnAction(new EventHandler<ActionEvent>() {
       @Override
       public void handle(ActionEvent e) {

       //Before  open a add effect here


        anchpane.setEffect(new BoxBlur(5, 10, 10)); // anchpane is anchor pane of main stage. change values of efect according your need. you can use any kind of pane of scene.  

        Stage usrpagestage = new Stage();
        usrpagestage.setMaxHeight(160);
        usrpagestage.setMaxWidth(210);
        usrpagestage.setResizable(false);
        usrpagestage.initStyle(StageStyle.UTILITY);
        usrpagestage.setScene(new Scene(new About()));
        usrpagestage.show();
    }
});

Look like :

enter image description here

When you close the stage set it to default.

 usrpagestage.setOnCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent t) {
         anchpane.setEffect(new BoxBlur(0, 0, 0));

        }
    });
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top