I am trying to continually create JLabels for every name in an ArrayList PantryNames. Here is my current code:
for(int i = 0; i < FoodApp.getPantryNames().size(); i++){
JLabel lblNewLabel = new JLabel((String) FoodApp.getPantryNames().get(i));
contentPane.add(lblNewLabel, BorderLayout.WEST);
}
I want the lblNewLabel to be set to "ingredient" + (i + 1). For example, the first food would be ingredient1 and so on. Additionally, in the contentPane, lblNewLabel would have to be ingredient + (i + 1). Thanks!