2
How do I open the file selection box and only choose songs with the extension .mp3
?
I am using Windowbuilder but the menu does not provide such option for quick creation.
2
How do I open the file selection box and only choose songs with the extension .mp3
?
I am using Windowbuilder but the menu does not provide such option for quick creation.
3
According to these two answers found in Soen:
JFileChooser
Apparently JFileChooser
not this gift by default, but you can add, follow the steps:
Go to system
and click on Choose Component
:
Now search for your component add it.
You’ll need the method getDescription
and accept
, example:
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 tested the code yet, but it seems to work, please let me know if there is any problem.
Browser other questions tagged java
You are not signed in. Login or sign up in order to post.
Post your code so the community can analyze.
– Weslley Tavares
Take a look here: https://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html. Well, I believe this is the path of stones to your doubt.
– Weslley Tavares
Despite a little poorly formulated the question, it is possible to answer yes within the context asked. For this I voted to leave open.
– Guilherme Nascimento