Open Folder to select file

2

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.

    
asked by anonymous 25.10.2015 / 15:30

1 answer

3

As both of these answers found in SOen :

Adding JFileChooser

Apparently JFileChooser is not present by default, but you can add, follow the steps:

  • Go to system and click Choose Component :

  • Nowlookforyourcomponenttoaddit.

  • Selecting File Types

    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.

        
    25.10.2015 / 17:36