For progress, there's also ProgressMonitor, which you can update on
any thread and it will pop up a progress meter if it looks like the
task will take a while (configurable).

On Wed, Feb 9, 2011 at 9:16 PM, Alexey Zinger <[email protected]> wrote:
> I fear invokeLater is greatly misunderstood :)  It's meant to be called by
> code running off the EDT to make something GUI-esque happen on EDT.  As
> you're trapping an event, you're on EDT, of course, so you gotta tap into a
> thread pool or spawn your own thread.  Haven't looked at SwingWorker
> approaches -- could be the best way to go.  So it seems the OP's answer
> would be to invokeLater and pop up the progress message, then go off into
> another thread and so the actual work and upon completion call invokeLater
> once more to update the GUI.
>
> Alexey
>
>
> ________________________________
> From: Ricky Clarkson <[email protected]>
> To: [email protected]
> Sent: Wed, February 9, 2011 4:12:09 PM
> Subject: Re: [The Java Posse] Re: Java Swing problem
>
> That invokeLater is entirely pointless.  You may as well write:
>
> private class ZoomListener implements ActionListener {
>     public void actionPerformed(ActionEvent ev) {
>         cardLayout.show(contentPane, "Progress Panel");
>         repaint();
>     }
> }
>
> Though I doubt you even need the repaint().
>
> On Wed, Feb 9, 2011 at 9:09 PM, Eric <[email protected]> wrote:
>> My first attempt at threading is a failure.  The gui still appears to
>> update only after my event method is complete.  I'll try to implement
>> your worker code.  Thanks.
>> Here's my apparently failed attempt.
>>
>> private class ZoomListener implements ActionListener {
>>     public void actionPerformed(ActionEvent ev) {
>>          loadProgress();
>> ...
>>     }
>> }
>> private void loadProgress() {
>>     Runnable doShowProgressPanel = new Runnable() {
>>          public void run() {
>>               cardLayout.show(contentPane, "Progress Panel");
>>               repaint();
>>          }
>>     };
>>     SwingUtilities.invokeLater(doShowProgressPanel);
>> }
>>
>> This code is all within my custom class which extends JFrame.
>>
>> On Feb 9, 3:44 pm, Ricky Clarkson <[email protected]> wrote:
>>> Doing it later but on the EDT isn't a good move.
>>>
>>> SwingWorker is the answer, though it's imo not the best API, as it
>>> swallows exceptions unless you override done() to call get().  Because
>>> of that, I use my own subclass of SwingWorker<Void, Void>, as follows:
>>>
>>> import java.util.concurrent.ExecutionException;
>>> import javax.swing.SwingWorker;
>>>
>>> public abstract class Worker extends SwingWorker<Void, Void> {
>>>     protected void afterDone() {
>>>     }
>>>
>>>     @Override
>>>     public final void done() {
>>>         try {
>>>             get();
>>>         } catch (InterruptedException e) {
>>>             throw new RuntimeException(e);
>>>         } catch (ExecutionException e) {
>>>             throw new RuntimeException(e);
>>>         }
>>>         afterDone();
>>>     }
>>>
>>> }
>>>
>>> If you have something else you want to do on the EDT after the
>>> contents of doInBackground() you just override afterDone().  Probably
>>> not the best naming, but it fills the hole.
>>>
>>>
>>>
>>> On Wed, Feb 9, 2011 at 8:32 PM, Alexey Zinger <[email protected]>
>>> wrote:
>>> > SwingUtilities.invokeLater FTW!
>>>
>>> > Alexey
>>> > 2001 Honda CBR600F4i (CCS)
>>> > 1998 Honda RS125 (CCS)
>>> > 2002 Suzuki Bandit 1200S
>>> >http://azinger.blogspot.com
>>> >http://bsheet.sourceforge.net
>>> >http://wcollage.sourceforge.net
>>>
>>> > ________________________________
>>> > From: Eric <[email protected]>
>>> > To: The Java Posse <[email protected]>
>>> > Sent: Wed, February 9, 2011 3:15:15 PM
>>> > Subject: [The Java Posse] Re: Java Swing problem
>>>
>>> > Odd that a request on Google Groups about which group to try for help
>>> > with Java got several responses all pointing to other websites.
>>> > In the lag time between making this post here and having it appear on
>>> > this group thread list I did find a Java group called
>>> > comp.lang.java.help.
>>> > I didn't exactly find the solution but I did figure out the problem.
>>> > I'm trying to execute some code in a Java event listener action method
>>> > which takes some time.
>>> > At the start of that method I want to show something on the screen to
>>> > let the user know it's processing.
>>> > At the end of the method I want it to show their new screen that
>>> > processing just generated.
>>> > The display from the start of the method never appears.  Apparently
>>> > Java won't update gui while it's processing.
>>> > It appears to be a threading issue.
>>>
>>> > On Feb 9, 10:40 am, Casper Bang <[email protected]> wrote:
>>> >> > Is this a good group for a programming question, or can anyone point
>>> >> > me to one?
>>>
>>> >> Nope this is more of a meta group, revolving around the JavaPosse GoF.
>>> >> Oracle have stirred the pot of established forums, but I do believe
>>> >> this is your best
>>> >> bet:http://forums.oracle.com/forums/forum.jspa?forumID=950
>>>
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> > Groups
>>> > "The Java Posse" group.
>>> > To post to this group, send email to [email protected].
>>> > To unsubscribe from this group, send email to
>>> > [email protected].
>>> > For more options, visit this group at
>>> >http://groups.google.com/group/javaposse?hl=en.
>>>
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> > Groups
>>> > "The Java Posse" group.
>>> > To post to this group, send email to [email protected].
>>> > To unsubscribe from this group, send email to
>>> > [email protected].
>>> > For more options, visit this group at
>>> >http://groups.google.com/group/javaposse?hl=en.- Hide quoted text -
>>>
>>> - Show quoted text -
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "The Java Posse" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/javaposse?hl=en.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "The Java Posse" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.
>
>
> ________________________________
> Now that's room service! Choose from over 150,000 hotels
> in 45,000 destinations on Yahoo! Travel to find your fit.
>
> --
> You received this message because you are subscribed to the Google Groups
> "The Java Posse" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to