DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Repainting progress bar from an event dispatching thread

  1. #1
    Bill Guest

    Repainting progress bar from an event dispatching thread


    I have a little java app that parses xml files. To set the maximum amount
    on my progress bar I first go through the xml files to get element count
    totals for all the files. Then, when I actually start parsing the file for
    content I fire an event from the startElement(), contentHandler callback
    method, that is received by the gui guy listening for these events. Inside
    this event handling, I'm updating my progress bar value. The current value
    attribute is being set correctly on the progress bar. The problem is that
    the gui is not repainted at this time to reflect the changed in appearance
    because the AWT event dispatching thread will not give the progressbar time,
    I think. Here is the code for the event handler to update the gui. My updateDisplay()
    just calls repaint()

    public void elementChanged(ElementEvent ee) {
    progressPanel.setProgressLabel("Loaded "+ee.getID()"of "+progressPanel.getTotalCount());
    progressPanel.setValue(ee.getID());
    progressPanel.updateDisplay();
    }

    How can I update the display of the progress bar inside this method?

    Thanks in advance,

    Bill

  2. #2
    Paul Clapham Guest

    Re: Repainting progress bar from an event dispatching thread

    Try "progressPanel.invalidate()". Or if progressPanel isn't your actual
    component, have it invalidate() the component.

    Bill <Bkhuff@aol.com> wrote in message news:3a785103$1@news.devx.com...
    >
    > I have a little java app that parses xml files. To set the maximum amount
    > on my progress bar I first go through the xml files to get element count
    > totals for all the files. Then, when I actually start parsing the file

    for
    > content I fire an event from the startElement(), contentHandler callback
    > method, that is received by the gui guy listening for these events. Inside
    > this event handling, I'm updating my progress bar value. The current

    value
    > attribute is being set correctly on the progress bar. The problem is that
    > the gui is not repainted at this time to reflect the changed in appearance
    > because the AWT event dispatching thread will not give the progressbar

    time,
    > I think. Here is the code for the event handler to update the gui. My

    updateDisplay()
    > just calls repaint()
    >
    > public void elementChanged(ElementEvent ee)


    > progressPanel.setProgressLabel("Loaded "+ee.getID()"of

    "+progressPanel.getTotalCount());
    > progressPanel.setValue(ee.getID());
    > progressPanel.updateDisplay();
    > }
    >
    > How can I update the display of the progress bar inside this method?
    >
    > Thanks in advance,
    >
    > Bill




  3. #3
    rubin Guest

    Re: Repainting progress bar from an event dispatching thread


    If you are parsing the XML file on the AWT-Event Thread, then you are tying
    up the same thread that paints the display. You need to throw your parsing
    off into a separate thread to free up the AWT-Event thread.
    If you are still having problems once you've done this, forcing a repaint(),
    and doing setVisible(true) can also help.



  4. #4
    Join Date
    Jan 2008
    Posts
    7

    Progress bar threading

    This sounds like an answer to my similar problem where I'm trying to 'DoEvents' while running a 3rd party dll. I believe I understand your instructions, but I have no idea how to implement them. Could you/anyone please provide some code snippets that would help get me started. Of course, a full VBP would be even better.

    THANKS!

  5. #5
    Join Date
    Jan 2008
    Posts
    7

    Progress bar threading

    This sounds like an answer to my similar problem where I'm trying to 'DoEvents' while running a 3rd party dll. I believe I understand your instructions, but I have no idea how to implement them. Could you/anyone please provide some code snippets that would help get me started. Of course, a full VBP would be even better.

    THANKS!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center