How to use FileDialog?

后端 未结 3 537
旧巷少年郎
旧巷少年郎 2020-12-10 11:14

I created an interface and I\'d like to add a function that allows user to open a file. I\'m using AWT. I don\'t understand how to use FileDialog. Can you please give me an

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 11:33

    To add to the answer by @TheBronx - for me, fd.setFile("*.txt"); is not working on OS X. This works:

    fd.setFilenameFilter(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".txt");
        }
    });
    

    Or as a fancy Java 8 lambda:

    fd.setFilenameFilter((dir, name) -> name.endsWith(".txt"));
    

提交回复
热议问题