That's what I tried at first and it didn't update the gui until that
entire actionPerformed method was complete.
Then I tried to use Sun's code.
http://java.sun.com/products/jfc/tsc/articles/threads/src/Example1.java

Either I missed something with that or they're missing something
there.

I looked up ProgressMonitor.  It seems that's only useful when you
have some idea how long the method will take and you can make calls to
update it in the middle of the processing.
My process makes a call to a method of another class where I don't
believe either would be easy, so my Progress Panel is simply a JPanel
containing a JProgressBar using indeterminate.

On Feb 9, 4:12 pm, Ricky Clarkson <ricky.clark...@gmail.com> wrote:
> 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 <e.d.program...@gmail.com> 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 <ricky.clark...@gmail.com> 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 <inline_f...@yahoo.com> 
> >> 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 <e.d.program...@gmail.com>
> >> > To: The Java Posse <javaposse@googlegroups.com>
> >> > 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 <casper.b...@gmail.com> 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 javaposse@googlegroups.com.
> >> > To unsubscribe from this group, send email to
> >> > javaposse+unsubscr...@googlegroups.com.
> >> > 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 javaposse@googlegroups.com.
> >> > To unsubscribe from this group, send email to
> >> > javaposse+unsubscr...@googlegroups.com.
> >> > 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 javaposse@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > javaposse+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://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 javaposse@googlegroups.com.
To unsubscribe from this group, send email to 
javaposse+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to