JFileChooser select directory but show files

后端 未结 9 1778
孤城傲影
孤城傲影 2020-12-11 00:49

I feel like there should be a simple way to do this but I can\'t figure it out. I have a JFileChooser that allows the user to select directories. I want to show all the file

9条回答
  •  醉话见心
    2020-12-11 01:38

    My solution is a merge between the answers of camickr and trashgod:

        final JFileChooser chooser = new JFileChooser() {
                public void approveSelection() {
                    if (getSelectedFile().isFile()) {
                        return;
                    } else
                        super.approveSelection();
                }
        };
        chooser.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES );
    

提交回复
热议问题