我使用登录名和密码启动了主窗口(类Main
)和模式窗口(类Login
)。主动模态窗口时,主阶段=
root.setEffect(new GaussianBlur());
如果用户有效,则模态窗口关闭。如何在主舞台重置效果
root.setEffect(new GaussianBlur());?
谢谢! 主要课程:
public class Main扩展Application {
Login loginWindow = new Login();
public static Stage windowMain;
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/views/main.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(this.getClass().getResource("/style/main.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
windowMain = primaryStage;
root.setEffect(new GaussianBlur());
loginWindow.display();
}
public static void main(String[] args) {
launch(args);
}
}
登录课程:
public class Login {
public void display() throws IOException {
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.initStyle(StageStyle.UNDECORATED);
auth.setTranslateY(40);
auth.setTranslateX(100);
auth.getStyleClass().add("auth");
TextField username = new TextField();
username.setTranslateY(70);
username.setTranslateX(75);
PasswordField password = new PasswordField();
password.setTranslateY(100);
password.setTranslateX(75);
Button loginBtn = new Button();
loginBtn.getStyleClass().add("loginBtn");
loginBtn.setStyle("-fx-cursor: hand");
loginBtn.setTranslateX(115);
loginBtn.setTranslateY(155);
loginBtn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if (username.getText().equals("admin") && password.getText().equals("admin")) {
window.close();
} else {
System.out.println("Error");
}
}
});
Pane layout = new Pane();
layout.getChildren().addAll(username, password, loginBtn);
Scene scene = new Scene(layout);
layout.getStylesheets().add(this.getClass().getResource("/style/login.css").toExternalForm());
username.setFocusTraversable(false);
password.setFocusTraversable(false);
window.setScene(scene);
window.setAlwaysOnTop(true);
window.showAndWait();
}
}
答案 0 :(得分:0)
default value for effect
is null,所以
root.setEffect(null);
应该有效。由于您在登录窗口中使用showAndWait()
,因此只需
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/views/main.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(this.getClass().getResource("/style/main.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
windowMain = primaryStage;
root.setEffect(new GaussianBlur());
loginWindow.display();
root.setEffect(null);
}