I am using the 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 a way to disable that option?

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

so something to add to above code which disallow user to select any other file?

有帮助吗?

解决方案

Take a look at JFileChooser#setAcceptAllFileFilterUsed

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top