I’m creating an application that gets a list of .java and .class files from a chosen directory and places them in a JList. I am using Netbeans 7.1.2.
At the moment i have the files being retrieved and being placed into a List<File>. I have all the files in the list printing out but i cannot add them to the JList the is in my form.
this is how i am adding the files to the list
List<File> filesInDirectory = new ArrayList<>();
public List listFilesForFolder(final File folder) {
for (final File fileEntry : folder.listFiles()) {
if (fileEntry.isDirectory()) {
listFilesForFolder(fileEntry);
} else {
if(fileEntry.toString().toUpperCase().endsWith(".CLASS") || fileEntry.toString().toUpperCase().endsWith(".JAVA")){
filesInDirectory.add(fileEntry);
System.out.println(fileEntry.getName());
}
}
}
return filesInDirectory;
}
Does anybody know how to do this?
1 Answer