Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6096755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:57:52+00:00 2026-05-23T12:57:52+00:00

In answering this question: I want to make a java program in which there

  • 0

In answering this question: I want to make a java program in which there is a combobox which displays the titles of all the files available in a folder

Another method of implementing the answer was brought to my attention; the usage of AudioSystem.getAudioFileTypes() to return all the supported audio files in the specified folder. I am a fairly inexperienced coder and am unable to integrate this method in my given answer

File someFolder = new File("pathname");

Object[] wavFiles = someFolder.listFiles(wavExtensionFilenameFilter);
JComboBox songComboBox = new JComboBox(wavFiles);

Can anyone show me how this would be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:57:53+00:00Added an answer on May 23, 2026 at 12:57 pm

    The following source will show a JFileChooser that is specific to file types understood by Java Sound. Once the user selects any sound clip, the app. will get a listing of all the clips in that directory and display them in a combo.

    Sound clip list

    On selecting a clip from the combo., we could play the sound in a javax.sound.sample.Clip (or other ways using the Java Sound API), but instead we opt. for the 1.6+ ‘one-liner’ of using Desktop to open the file (in the system default player).

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.filechooser.FileNameExtensionFilter;
    import javax.sound.sampled.*;
    import java.io.*;
    
    class GetSoundsByFileType {
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    AudioFileFormat.Type[] formatTypes = AudioSystem.getAudioFileTypes();
                    String[] types = new String[formatTypes.length];
                    for(int ii=0; ii<types.length; ii++) {
                        types[ii] = formatTypes[ii].getExtension();
                    }
    
                    FileTypesFilter fileTypesFilter = new FileTypesFilter(types);
                    // Just to confuse things, JFileChooser accepts a
                    // different type of filter!
                    FileNameExtensionFilter extensionFilter =
                        new FileNameExtensionFilter("Sound clips", types);
                    JFileChooser fc = new JFileChooser();
                    fc.setAcceptAllFileFilterUsed(false);
                    fc.addChoosableFileFilter(extensionFilter);
    
                    int result = fc.showOpenDialog(null);
                    if (result==JFileChooser.APPROVE_OPTION) {
                        File startAt = fc.getSelectedFile();
    
                        startAt = startAt.getParentFile();
                        File[] files = startAt.listFiles(fileTypesFilter);
    
                        final JComboBox clipCombo = new JComboBox(files);
                        clipCombo.addActionListener( new ActionListener(){
                                // 1.6+
                                Desktop desktop = Desktop.getDesktop();
    
                                public void actionPerformed(ActionEvent ae) {
                                    try {
                                        desktop.open( (File)clipCombo.getSelectedItem() );
                                    } catch(Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            } );
    
                        JOptionPane.showMessageDialog(null, clipCombo);
                    }
                }
            });
        }
    }
    
    class FileTypesFilter implements FilenameFilter {
    
        private String[] types;
    
        FileTypesFilter(String[] types ) {
            this.types = types;
        }
    
        public boolean accept(File dir, String name) {
            for (String type:types) {
                if (name.toLowerCase().endsWith(type.toLowerCase())) {
                    return true;
                }
            }
            return false;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In answering this question ( https://stackoverflow.com/questions/352317/c-coding-question#352327 ), it got me wondering... Is there any
I'll be answering this question I want to allow my users to upload multiple
Thanks for helping me answering this question, I want to update the user's location
There are many questions related to Stackless Python. But none answering this my question,
In answering this question , it got me thinking... I often use this pattern:
In answering this code golf question , I ran across a problem in my
I'm writing this question in the spirit of answering your own questions, since I
This came up when answering another user's question (TheSoftwareJedi)... Given the following table: ROW_PRIORITY
This is a complex question, please consider carefully before answering. Consider this situation. Two
I'm posting this in the spirit of answering your own questions. The question I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.