【问题标题】:Is it possible to select multiple directories at once with JFileChooser是否可以使用 JFileChooser 一次选择多个目录
【发布时间】:2013-01-08 18:00:34
【问题描述】:

正如标题所述,有没有办法使用 JFileChooser 一次选择多个目录(主目录中的所有子目录),这样我就不必为每个目录重新打开文件选择器窗口?

【问题讨论】:

    标签: java jfilechooser directory


    【解决方案1】:

    在提出问题后,我再次解决了自己的问题。

    之前阻止我让它工作的事情是我使用了多选检查而不是多选设置,显然是使用了错误,而且我一直收到错误。无论如何,工作版本如下:

    class AddDirectory implements ActionListener {
        public void actionPerformed(ActionEvent ae) {
            File[] theDir = null;
            theDir = selectDir();
            if(theDir != null) {
                for(File z : theDir) {
                    String[] curRow = { z.toString(), "Waiting"};
                    dlm.addRow(curRow);
                }
            }
            return;
        }   
        private File[] selectDir() {
            JFileChooser fileChooser = new JFileChooser(lastDir);
            fileChooser.setMultiSelectionEnabled(true);
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int showOpenDialog = fileChooser.showOpenDialog(null);
            if (showOpenDialog != JFileChooser.APPROVE_OPTION) {
                return null;
            }
            File[] uploadDir = fileChooser.getSelectedFiles();
            lastDir = new File(uploadDir[uploadDir.length-1].getParent());
            return uploadDir;
        }
    }
    

    获得目录后,它们会被加载到 JTable 中以进行修改,然后再在其上运行我的其余代码。

    【讨论】:

      猜你喜欢
      • 2017-11-08
      • 2021-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-16
      • 2015-05-08
      • 2021-01-16
      • 1970-01-01
      相关资源
      最近更新 更多