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
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.
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