-
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
-
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
-
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.
-
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!
-
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
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|