0

I have developed a simple swing application in which i am running a process using SwingWorker and showing an indeterminate progress bar to end user while the process is running.

As soon as the process is complete I am setting the visibility of ProgressDialog false in done() method of SwingWorker.

Now the problem is when end user clicks on parent window it is getting focused and progress dialog is going back to the main window which I don't want when i tried to set modality of dialog as true it is holding my program there only and my SwingWorker thread doesn't start at all.

As I am a very new for Swing let me know how can I achieve both things together.

My swingworker should stop as well as user should not be able to click on main as happened when we set modality tru for a dialog.

Code Snippet :

ProgressDialog myProgressDialog = new ProgressDialog();
myProgressDialog.setVisible(true);
myProgressDialog.setLocationRelativeTo(this);

mySwingWorkerForUpdate = new SwingWorker<String, String>() {

 @Override
 protected String doInBackground() throws Exception {
               //my code here
 }

  @Override
  protected void done() {
      super.done(); 
      mySwingWorkerForUpdate = null;
      myProgressDialog,setVisibility(false);
  }
};

 mySwingWorkerForUpdate.execute();
Piyush Agarwal
  • 25,608
  • 8
  • 98
  • 111
  • 3
    Make the dialog modal but call `setVisible(true)` _after_ you start the worker – DannyMo Jul 31 '13 at 19:53
  • After Setting modality true new issue came `myProgressDialog.setLocationRelativeTo(this);` stopped working and my dialog is coming on left corner of the machine all the time. – Piyush Agarwal Jul 31 '13 at 20:00
  • it is solved by making call after all the location set . Thanks alot – Piyush Agarwal Jul 31 '13 at 20:04
  • 1
    see [this answer](http://stackoverflow.com/a/10240173/1671856) to a previous question – DannyMo Jul 31 '13 at 20:47
  • 1
    @damo: I like that answer. ;) Your first comment should probably be posted as an answer here. – Hovercraft Full Of Eels Jul 31 '13 at 21:28
  • 1
    @HovercraftFullOfEels I flagged the question as a duplicate instead of answering. There seems to be quite a few questions which ask the same thing – DannyMo Jul 31 '13 at 21:37
  • possible duplicate of [How do I make my SwingWorker example work properly?](http://stackoverflow.com/questions/10236995/how-do-i-make-my-swingworker-example-work-properly) – Richard Sitze Aug 01 '13 at 01:01
  • Ya the the link is having the same question but the topic is not correct as the question so i did not get it in google search. Anyway Thanks for the answer you can put the Link in answer so i will accept it as an answer . – Piyush Agarwal Aug 01 '13 at 11:11

0 Answers0