How do I open the file select box and only choose songs with the .mp3
extension?
I'm using Windowbuilder but the menu does not provide such an option for quick build.
How do I open the file select box and only choose songs with the .mp3
extension?
I'm using Windowbuilder but the menu does not provide such an option for quick build.
As both of these answers found in SOen :
JFileChooser
Apparently JFileChooser
is not present by default, but you can add, follow the steps:
Go to system
and click Choose Component
:
Nowlookforyourcomponenttoaddit.
You will need the method getDescription
and accept
, eg:
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter(new FileFilter()
{
public String getDescription() {
return "Audio Files (*.mp3)";
}
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
} else {
String filename = f.getName().toLowerCase();
return filename.endsWith(".mp3");
}
}
});
I have not yet tested the code, but it seems to work, please let me know if there is any problem.