我现在正试着把焦点放在FX FileDialog上。当我在对话框外单击时,对话框处于离线状态。有没有办法让我在外面点击的时候,对话框调用任何让他可见(聚焦)的方法?TY :)
我刚试过像这样的。
...focusedProperty().addListener((obs, oldVal, newVal) -> System.out.println(newVal ? "Focused" : "Unfocused"));梅比走这边..。
fileChooser.addEventHandler(WindowEvent.WINDOW_SHOWN, new EventHandler<WindowEvent>(){
@Override
public void handle(WindowEvent window)
{...发布于 2017-11-23 19:35:43
在javafx.stage.FileChooser中无法使用addEventHandler处理焦点,但您可以简单地使用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);
}
}https://stackoverflow.com/questions/47452204
复制相似问题