문제

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