This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm making simple gallery, and i have small problem. I have for List of 20 JButtons (which icon is my Image). I don't want to add MouseListeners to each JButton. And i tried to add Action Listener in a loop. I tried something like this:
and it doesn't work, because button wasn't pressed. licznik (my counter variable) counts from 1 to 20,"while" loop sets action listener for every JButton, but when I click on my JButton it always display last image on the list (number 20).
I think i would have to click the JButton on each iteration. I tried also with something like this:
And it also doesn't work. It makes "clicks", but when I click on any button in my gallery it always displays last image.
Is it possible to add action/mouse listeners in a loop to the List of Components?