2017-11-23 9 views
2

私は現在、FX FileDialogに焦点を合わせようとしています。ダイアログの外をクリックすると、ダイアログがアウトフォーカスされます。私が外をクリックすると、そのダイアログは彼に見える(焦点を合わせる)すべてのmetodを呼び出します。 TY :)JavaFX FileDialogフォーカス

私はちょうどこれを試しました。

...focusedProperty().addListener((obs, oldVal, newVal) -> System.out.println(newVal ? "Focused" : "Unfocused")); 

、この方法をmaebyは...

fileChooser.addEventHandler(WindowEvent.WINDOW_SHOWN, new EventHandler<WindowEvent>(){ 
         @Override 
         public void handle(WindowEvent window) 
         {... 

答えて

0

addEventHandlerjavafx.stage.FileChooser内部 を使用して焦点を当てて処理する方法はありません。しかし、あなたは、単に他の上ごFileChooserが常に見えるようにするprimaryStage.setAlwaysOnTop(true);を使用することができますウィンドウ

import javafx.application.Application; 
import javafx.event.ActionEvent; 
import javafx.event.EventHandler; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.layout.StackPane; 
import javafx.stage.FileChooser; 
import javafx.stage.Stage; 


public class JavaFXtest5 extends Application { 

    @Override 
    public void start(Stage primaryStage) { 
     Button btn = new Button(); 
     btn.setText("Test"); 

     FileChooser chooser = new FileChooser(); 

     btn.setOnAction(new EventHandler<ActionEvent>() { 

      @Override 
      public void handle(ActionEvent event) { 
       primaryStage.setAlwaysOnTop(true); 
       chooser.showOpenDialog(primaryStage); 
       primaryStage.setAlwaysOnTop(false); 
      } 
     }); 

     StackPane root = new StackPane(); 
     root.getChildren().add(btn); 

     Scene scene = new Scene(root, 300, 250); 

     primaryStage.setTitle("Hello Dialog!"); 
     primaryStage.setScene(scene); 
     primaryStage.show(); 
    } 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) { 
     launch(args); 
    } 

} 
関連する問題