Reputation: 1813
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 ?
Upvotes: 2
Views: 1382
Reputation: 3126
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 :
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));
}
});
Upvotes: 4