2016-04-06 4 views
0

私はメインウィンドウ(クラスMain)とモーダルウィンドウ(クラスLogin)をログインとパスワードで開始しました。モーダルウィンドウをアクティブにしながら、メインステージ=javafxでエフェクトをリセットするには?

root.setEffect(new GaussianBlur()); 

有効なモーダルウィンドウが閉じている場合。メインステージのエフェクトをリセットする方法

root.setEffect(new GaussianBlur());? 

ありがとうございます! 主なクラス:

主延び

パブリッククラスアプリケーション{

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 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

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); 
} 
+0

ありがとうございます。しかし、どのように私はメインクラスのシーンを取得できますか? –

+0

コメントにコードを入れず、質問を編集して、フォーマットされたコードを質問に追加してください。 – jewelsea

+0

James_D、ありがとう! –

関連する問題