views:

31

answers:

2

As I said, i have a java desktop application. The interface contains a JList and I modify the content of this list in some custom listeners that i implemented.

One of the listeners iterates through all the items in the list and performs some operations that may take a while. I would like to show the user the item that I am currently at. For starters, I just tried iterating through the elements in the list and just setting the selected index and then calling repaint (i do these 2 operations for each item). What happens is that there is no change in the interface during this iteration until the end, when the last item does get marked as selected.

Does anyone have I hint as to why this might be happening and how to show a change in selection in A JList?

Thank you, Mihaela

+1  A: 

You seem to be doing your time-consuming operations in the same thread that is responsible for updating your GUI (the Event Dispatching Thread). Your application freezes until the operation is done.

Have a look at Threads and Swing to understand the problem, and at Using a Swing Worker Thread for examples on how to fix this.

Peter Lang
wow, that was a fast reply. thank you.
mihaela
+1  A: 

For someone who needs to learn about concurrency in swing, as was my case, I think the following link is also of great help: Concurrency in Swing

mihaela