Displaying real-time "console-like" output
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Edward_Maybert
Posted On:   Tuesday, September 16, 2003 04:32 PM

I am writing a Swing app that basically processes files in a directory tree. I would like to display, to the user, each file as it's being processed, in "real-time". My initial approach was to use a JList backed by a Vector of files. So, for each file processed, I: 1. Add the file to the Vector 2. Update the JList with setListData(Vector) 3. Try to update the view with SwingUtilities.updateComponentTreeUI(this); This doesn't work though, as the list doesn't update until all the files are done processing. Is there a better way to attack this? Any help would be greatly appreciated. ~ed   More>>

I am writing a Swing app that basically processes files in a directory tree. I would like to display, to the user, each file as it's being processed, in "real-time".


My initial approach was to use a JList backed by a Vector of files. So, for each file processed, I:

1. Add the file to the Vector

2. Update the JList with setListData(Vector)

3. Try to update the view with SwingUtilities.updateComponentTreeUI(this);


This doesn't work though, as the list doesn't update until all the files are done processing.


Is there a better way to attack this?


Any help would be greatly appreciated.

~ed

   <<Less

Re: Displaying real-time "console-like" output

Posted By:   Bahman_Barzideh  
Posted On:   Wednesday, September 17, 2003 04:51 AM

I realize you are looking for a better design but you can try the following on your
current program to see if it does what you want.

  • Create a custom list model for your JList. You do this by implementing the ListModel interface and installing on your
    JList. With this class you won't need to reload the JList with every file each time a new one is processed (you can remove the call to list.setListData ()). You
    simply add the new file to the model (probably through a special method
    that is not required by ListModel

  • When you are ready to update the view (I guess after each file is added
    to the model) call the following:

    list.revalidate (); // list.invalidate () may also work here
    list.repaint ();

    instread of calling SwingUtilities.updateComponentTreeUI(this);
  • About | Sitemap | Contact