FileFilter for JFileChooser

后端 未结 5 1502
走了就别回头了
走了就别回头了 2020-12-17 15:45

I want to restrict a JFileChooser to select only mp3 files. But, the following code allows all file types:

FileFilter filter = new FileNameExten         


        
5条回答
  •  [愿得一人]
    2020-12-17 16:04

    fileChooser.addChoosableFileFilter(filter) will add a custom file filter to the list of user-choosable filters. By default, the list of user-choosable filters includes the Accept All filter, which enables the user to see all non-hidden files.

    You will need to invoke: fileFilter.setAcceptAllFileFilterUsed(false)

    The setAcceptAllFileFilterUsed(boolean) determines whether the AcceptAll FileFilter is used as an available choice in the choosable filter list. If false, the AcceptAll file filter is removed from the list of available file filters. If true, the AcceptAll file filter will become the the actively used file filter.

提交回复
热议问题