I am trying to create a program to shuffle music. I have already gotten all the songs imported, and now I am trying to create a ``JCheckBox for each song. I have a for loop that creates these checkboxes, but I need a way to test if the box is checked. I am already using if(box.isSelected()), but need to discern which box, and need to access box outside the for loop.
Here is my code.
By the way, songs
is an ArrayList
.
public static void checkboxList() {
ArrayList<JCheckBox> checkboxes = new ArrayList<>();
for (String element : songs) {
System.out.println("Reached checkbox thing");
System.out.println(element);
JCheckBox box = new JCheckBox(element);
checkboxes.add(box);
panel.add(box);
frame.pack();
}
int loop = 0;
while (loop == 0) {
if (checkboxes.contains(box.isSelected())) {
}
}
}