Results 1 to 9 of 9
  1. #1
    Brad is offline Member
    Join Date
    Feb 2012
    Posts
    21
    Rep Power
    0

    Default JDialog doesn't close in SwingWorker

    After kicking off a thread I have SwingWorker kicking up a JDialog (called Process) that has an indeterminate progress bar on it. The dialog shows up alright, but it never closes when the thread ends. I call Progress.dispose() in my done() method but it doesn't see to work. Any ideas?

    Java Code:
     //********************************************************************      
                final Thread runLoad = new Thread(new loadRepo(command));
                runLoad.start();
          //********************************************************************
                
              SwingWorker worker = new SwingWorker<Void, Void>(){         
                @Override
                protected Void doInBackground() throws Exception {
                        while (runLoad.getState() != Thread.State.TERMINATED && !isCancelled()) {
                            try {
                                Progress.setTitle("Loading Repository");
                                Progress.setLocationRelativeTo(null);
                                Progress.setVisible(true);
                                synchronized (this) {
                                    Thread.sleep(2000);
                                }
                            } catch (InterruptedException e) {
                                JOptionPane.showMessageDialog(null,
                                        "Process interrupted: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                            }
                        }
                        return null;
                    }
                @Override
                    public void done() {
                        Progress.setVisible(false);
                        Progress.dispose();
                    }
                };
                worker.execute();

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,609
    Rep Power
    5

    Default Re: JDialog doesn't close in SwingWorker

    Please include all of your code as we can't see what is happening with what you provided. Also, please keep it small (justenought to demonstrate
    the problem). Just create two SwingWorker threads, one with a JDialog and the one where you want to close it. Keep it simple please, less than 50 lines.
    And make certain we can compile it (i.e. a complete, syntax free program).

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,524
    Blog Entries
    7
    Rep Power
    20

    Default Re: JDialog doesn't close in SwingWorker

    Quote Originally Posted by jim829 View Post
    (i.e. a complete, syntax free program).
    That was a slip of the finger, I'm sure; actually I'm very interested in (almost) syntax free programming languages; forth and lisp inspired me years ago and I came up with a form of RPL (Reverse Polish Lisp) and added some features I stol^H^H^H^Hborrowed from a few other languages. The result still surprises me now and then although I'm afraid the resulting programs are not what others would call readable ;-) (functional language programmers find it fascinating, Java addicts find it completely unreadable because of its terseness).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,009
    Rep Power
    20

    Default Re: JDialog doesn't close in SwingWorker

    Why are you launching this in a separate thread?
    It's all supposed to sit on the EDT anyway, since it's all GUI stuff.
    The worker should be doing the work, not showing dialogs.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,609
    Rep Power
    5

    Default Re: JDialog doesn't close in SwingWorker

    Lol. Yes, I meant syntax error free of course. Boy, last night was a bad night. I must have been in a fog when I was replying to these threads.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,016
    Rep Power
    6

    Default Re: JDialog doesn't close in SwingWorker

    Quote Originally Posted by jim829 View Post
    Lol. Yes, I meant syntax error free of course. Boy, last night was a bad night. I must have been in a fog when I was replying to these threads.

    Regards,
    Jim
    A colleague of mine had this saying: all the work you do after 8PM is lost effort. I guess it also applies to answering questions ;)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,009
    Rep Power
    20

    Default Re: JDialog doesn't close in SwingWorker

    We had a similar one back in the 90s, though that involved any work done on a Friday afternoon after lunch down the pub.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,524
    Blog Entries
    7
    Rep Power
    20

    Default Re: JDialog doesn't close in SwingWorker

    Quote Originally Posted by gimbal2 View Post
    A colleague of mine had this saying: all the work you do after 8PM is lost effort. I guess it also applies to answering questions ;)
    For reasons of symmetry, all work done before 8:00pm is also lost; I anticipate on that ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,609
    Rep Power
    5

    Default Re: JDialog doesn't close in SwingWorker

    Everything has a way of working out. If I hadn't made that silly error, I wouldn't of gotten my lesson in philosophy.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. JDialog close option
    By fam2315 in forum AWT / Swing
    Replies: 1
    Last Post: 08-03-2011, 06:36 PM
  2. my JDialog doesn't want to resize as I say :P
    By patr1c1a in forum New To Java
    Replies: 3
    Last Post: 11-25-2010, 02:12 PM
  3. Close JDialog
    By sky in forum AWT / Swing
    Replies: 7
    Last Post: 11-16-2009, 06:01 PM
  4. Close a JDialog Programmatically
    By Marcus in forum Advanced Java
    Replies: 1
    Last Post: 07-06-2007, 04:06 PM
  5. Replies: 1
    Last Post: 04-09-2007, 12:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •