So, I figured out the SwingWorker thing.
However, another problem emerged (go figure)...
Swing worker acctually manages error reporting and email sending, and emailing being a lenghty (more than .5 seconds) task, it comes in handy...
In order to prevent my program to continu executing before the error has been processed, I have to pause the EDT thread (with that syncronised thingy). However, that will also pause cool little animation that indetermined JProgressBar has, and which is being used while the message is sent, so, when the EDT is paused.
My question is, is there any way to stop my program from continuing to execute, and at the same time dispaly the animation on JProgressBar?
Here is somwhat pseudo code:
Main class error occurrs - pauses thread with syncronised and executes (creates) another class that executes SwingWorker (that another class is neccessary, it really is, if it weren't I wouldn't be having so much trouble with this).
new ErrorDialog(Main.modal, lang.getString("errorConfigMissingTitle"), lang.getString("errorConfigMissingMessage"), e, false);
It invokes this:
//bunch of code, this below is an action listener of one of the buttons
String s = "";
(new ErrorSender(parent, error, s, dialog)).execute();
synchronized (s)
{
try
{
s.wait();
}
catch (InterruptedException e1)
{
e1.printStackTrace();
}
}
dialog.dispose();
//create JDialog that tell user message was sent
SwingWorker class creates sendingErrorReport JDialog (with JProgressBar) and sends the message in the background, when message is sent, removes pause (notyfyAll()).
public class ErrorSender extends SwingWorker<Boolean, Void>
{
Exception e;
String s;
public ErrorSender(JFrame parent, Exception error, String k, JDialog sendingDialog)
{
e = error;
s = k;
sendingDialog = new JDialog(parent, "Sending...", false);
JProgressBar progress = new JProgressBar();
progress.setString("Sending report...");
progress.setStringPainted(true);
progress.setIndeterminate(true);
sendingDialog.getContentPane().add(progress);
sendingDialog.pack();
sendingDialog.setLocationRelativeTo(null);
sendingDialog.getContentPane().validate();
sendingDialog.setResizable(false);
sendingDialog.setVisible(true);
}
@Override
protected Boolean doInBackground() throws Exception
{
//send email here
synchronized (s)
{
s.notifyAll();
}
return null;
}
}
I'm not removing pause from done() method because, if pause is not removed, done() is never reached/called...