A
andrej.zirko
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
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