JFileChooser select directory but show files

后端 未结 9 1771
孤城傲影
孤城傲影 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

    Override the approveSelection() method. Something like:

    JFileChooser chooser = new JFileChooser( new File(".") )
    {
        public void approveSelection()
        {
            if (getSelectedFile().isFile())
            {
                // beep
                return;
            }
            else
                super.approveSelection();
        }
    };
    

提交回复
热议问题