Disable All Files when using FileNameExtensionFilter in java

I use FileNameExtensionFilter to filter the file type, but when the user selects the open button, they have the option to select "All files" from the file type. is there any way to disable this option?

FileFilter filter = new FileNameExtensionFilter("JPEG file", "jpg", "jpeg"); JFileChooser fileChooser = ...; fileChooser.addChoosableFileFilter(filter); 

so something to add to the above code that prevents the user from selecting any other file?

+6
source share
1 answer

Take a look at JFileChooser#setAcceptAllFileFilterUsed

Determines whether AcceptAll FileFilter is used as an available selection in the list of favorite filters. If false, the AcceptAll filter file is removed from the list of available file filters. If true, the AcceptAll file filter will become an actively used file filter.

+12
source

All Articles