• JavaFX DirectoryChooser[目录选择器]使用实例及源代码[图文]


    一. 运行效果图





    二. 源代码

    package helloworld;

     
    import java.io.File;


    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.DirectoryChooser;
    import javafx.stage.DirectoryChooserBuilder;
    import javafx.stage.Stage;
    import javafx.stage.Window;
     
    public class HelloWorld extends Application {
        public static void main(String[] args) {
            launch(args);
        }
        
        @Override
        public void start(final Stage primaryStage) {
            primaryStage.setTitle("Hello World!");
            final Button btn = new Button();
            btn.setText("Say 'Hello World'");
            btn.setOnAction(new EventHandler<ActionEvent>() {

                public void handle(ActionEvent event) {
                    DirectoryChooserBuilder builder = DirectoryChooserBuilder.create();
                    builder.title("Hello World");
                    String cwd = System.getProperty("user.dir");
                    File file = new File(cwd);
                    builder.initialDirectory(file);
                    DirectoryChooser chooser = builder.build();
                    File chosenDir = chooser.showDialog(primaryStage);
                    if (chosenDir != null) {
                      System.out.println(chosenDir.getAbsolutePath());
                    } else {
                     System.out.print("no directory chosen");
                    }
                }
            });
            
            StackPane root = new StackPane();
            root.getChildren().add(btn);
            
            primaryStage.setScene(new Scene(root, 300, 250));
            primaryStage.show();
        }
    }
  • 相关阅读:
    nginx-rtmp-module
    nginx搭建支持http和rtmp协议的流媒体服务器之一
    用开源nginx-rtmp-module搭建flash直播环境
    Nginx RTMP 功能研究
    开源的视频直播
    LeetCode题解之Rotate String
    LeetCode题解之 Letter Case Permutation
    LeetCode题解之 3Sum
    LeetCode 题解之 Two Sum
    LeetCode 题解之Linked List Cycle II
  • 原文地址:https://www.cnblogs.com/leonxyzh/p/7289158.html
Copyright © 2020-2023  润新知