Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

JDialog displaying progress

Thread view: 
andrej.zirko@gmail.com - 17 Dec 2006 01:50 GMT
Hi,
I'm trying to display on modal JDialog progress of copying files. I've
used SwingWorker for copying the files, so it won't freeze the JDialog,
but then I need to get the response to parent frame (if the files were
copied succesfully). I've tried StringWorker.get but when I use this
method the JDialog won't show up :(

//Creating dialog from MainFrm and executing download method
       final CopyDlg copyDlg = new CopyDlg(this, true);
       SwingUtilities.invokeLater(new Runnable() {
           public void run() {
               copyDlg.setVisible(true);
           }
       });

       try {
               sWorker = copyDlg.download(toCopy,
currentDirectory.getPath(), remoteDirectories, ftp, jLogTxtArea);
               System.out.println(sWorker.get()); //without this line
it's working ok, but I don't get response :\
           } catch (InterruptedException ex) {
               ex.printStackTrace();
          }
//-----------------------------------------------------------------------------------------------------------------------------------------------
//method download in CopyDlg class
   public SwingWorker download(final ArrayList foDs, final String
where, final FDArrayList directories, FtpClient ftp, JTextArea
jLogTxtArea) throws InterruptedException {
       this.ftp = ftp;
       this.jLogTxtArea = jLogTxtArea;

       SwingWorker sWorker = new SwingWorker<Boolean, Void>() {
           public Boolean doInBackground() throws Exception {
               String foD;

               for (int x = 0; x < foDs.size(); x++){
                   foD = (String) foDs.get(x);

                   if (!downloadFoD(foD, where, directories))
                       return false;
               }

               return true;
           }

           public void done(){
               setVisible(false);
           }
       };

       sWorker.execute();

//        try {
//            System.out.println(sWorker.get());
//        } catch (InterruptedException ex) {
//            ex.printStackTrace();
//        } catch (ExecutionException ex) {
//            ex.printStackTrace();
//        }

       return sWorker;
   }

I'm newbie to Java so please be patient :)
Any help is appreciated
Thanks in advance ;)
hiwa - 17 Dec 2006 02:47 GMT
> Hi,
> I'm trying to display on modal JDialog progress of copying files. I've
[quoted text clipped - 62 lines]
> Any help is appreciated
> Thanks in advance ;)
Read the API documentation of the SwingWorker.get() method and try
calling the get() method from within the SwingWorker.done() method.
That should be a peaceful and safe way for getting the result from a
long task.
andrej.zirko@gmail.com - 17 Dec 2006 16:54 GMT
Thanks works fine ;)
I've done it like this

           public void done(){
               setVisible(false);
               ((MainFrm)getParent()).showResponse(this, "Can't copy
selected items!", false);
           }

But I have another question :)

I've read on java tutorials, that I should also create my dialog in
invokeLater, but how can I do that? :\ The CopyDlg has to be final, if
I want to use him in invokelater. If I'll put just declaration of
CopyDlg outside the invokeLater statement, It won't be final any more.
And if I'll put declaration with creation inside invokeLater statement,
I can't invoke download or upload method outside invokeLater :\
I'm really confused here - please help ;) :)

BTW Everything works fine now, but I just want to have it as it should
be. :)

hiwa nap?sal(a):
> > Hi,
> > I'm trying to display on modal JDialog progress of copying files. I've
[quoted text clipped - 66 lines]
> That should be a peaceful and safe way for getting the result from a
> long task.
hiwa - 18 Dec 2006 04:23 GMT
> Thanks works fine ;)
> I've done it like this
[quoted text clipped - 89 lines]
> > That should be a peaceful and safe way for getting the result from a
> > long task.
Sorry, I don't understand your story...
Could you show some code example or a pseudo code?
Talking about code without SSCCE is quite inefficient.
Post a small demo code that is generally compilable, runnable and could
reproduce your problem. See:
http://homepage1.nifty.com/algafield/sscce.html and
http://www.yoda.arachsys.com/java/newsgroups.html
andrej.zirko@gmail.com - 18 Dec 2006 13:11 GMT
> Sorry, I don't understand your story...
> Could you show some code example or a pseudo code?
[quoted text clipped - 3 lines]
> http://homepage1.nifty.com/algafield/sscce.html and
> http://www.yoda.arachsys.com/java/newsgroups.html

I'm still talking about the code in my first post
//Creating dialog from MainFrm and executing download method
       final CopyDlg copyDlg = new CopyDlg(this, true);
       SwingUtilities.invokeLater(new Runnable() {
           public void run() {
//I WANT TO HAVE CREATION OF COPYDLG HERE - new CopyDlg(this, true);
               copyDlg.setVisible(true);
           }
       });

       try {
               sWorker = copyDlg.download(toCopy,
currentDirectory.getPath(), remoteDirectories, ftp, jLogTxtArea);
               System.out.println(sWorker.get()); //without this line
it's working ok, but I don't get response :\
           } catch (InterruptedException ex) {
               ex.printStackTrace();
          }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.