I am trying to read all the file name from a specific folder and trying to create multiple checkbox in JFrame with the same name. So, if there are 5 files in the folder, application should show 5 checkboxes in the frame.
Here is my code.
JFrame frame = new JFrame();
File folder = new File("C://Tests");
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("File " + listOfFiles[i].getName());
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory " + listOfFiles[i].getName());
}
JCheckBox checkbox[i] = new JCheckBox(listOfFiles[i].getName());
}
But I am getting error "Type mismatch: cannot convert from JCheckBox to JCheckBox[]". Can someone please tell me what am I doing incorrect ?
Appreciate any help. Thanks
Aucun commentaire:
Enregistrer un commentaire