What I am trying to achieve is have one JLabel
to display multiple items from a List
.
I have defined the list as below but when I test the code
Your current code always overrides the current text in the JPanel, and it does that so fast, that you don't see it. Instead of using the Iterator, get the next item in the list by defining an int variable that gets incremented every press.
The index
variable is a public int in this example:
jLabel1.setText(strings.get(index));
if (index < strings.size()-1)
index++;
No loops, that's everything needed in your method.