File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Force ListCellRenderer to update GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Force ListCellRenderer to update GUI" Watch "Force ListCellRenderer to update GUI" New topic

Force ListCellRenderer to update GUI

Fintan Conway
Ranch Hand

Joined: Apr 03, 2002
Posts: 141
Hi All,
I have a JList which shows a list of files. I can programmatically grab the selected files and loop through each file - performing operations on it.
What I want to do is change the background of a file once it has been processed to show the status of the file (Green = OK, Red = Fail).
I am storing the index of the files in 2 ArrayLists - one for the good files and one for the bad files.
I have created the ListCellRenderer which will set the appropriate background depending on whether a file is in one of the ArrayLists or not.
The problem is that the custom ListCellRenderer only updates the JList AFTER all files have been processed. I want the JList to be updated after each individual file has been processed. Is this possible?
I have added Thread.yield() and Thread.sleep(5000) and JList.repaint() in the loop that processes each file - but these do not work.
Can anyone help me?
Many thanks,
PS Here is the code that loop thro' each file :

Here is the getListCellRendererComponent method of my ListCellRenderer :
phil marquet

Joined: Dec 18, 2002
Posts: 1
for(int i = 0; i < userListModel.size(); i++) {
userListModel.setElementAt(userListModel.getElementAt(i), i);

I agree. Here's the link:
subject: Force ListCellRenderer to update GUI
It's not a secret anymore!