JavaFX FileDialog焦点

时间:2017-11-23 09:42:51

标签: java javafx javafx-8 filedialog

我现在正试图关注FX FileDialog。当我在对话框外面单击时,对话框会失控。当我点击外面的任何方式,对话框调用任何使他可见(聚焦)的metod? TY:)

我刚试过这样的事。

...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)
                        {...

1 个答案:

答案 0 :(得分:0)

使用javafx.stage.FileChooser内的primaryStage.setAlwaysOnTop(true);无法处理焦点,  但是,您只需使用FileChooser即可使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); } } 始终在其他窗口上显示

feed_entries