I want to restrict a JFileChooser to select only mp3 files. But, the following code allows all file types:
FileFilter filter = new FileNameExten
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.