I want to restrict a JFileChooser
to select only mp3 files. But, the following code allows all file types:
FileFilter filter = new FileNameExtensionFilter("MP3 File","mp3");
fileChooser.addChoosableFileFilter(filter);
fileChooser.showOpenDialog(frame);
File file = fileChooser.getSelectedFile();
Try and use fileChooser.setFileFilter(filter)
instead of fileChooser.addChoosableFileFilter(filter);