в методе процесса SwingWorker
Если вы имеете в виду:
a) внутри doInBackground (),
public Boolean doInBackground() {
// caught exception half way e.g. login auth fail
// 'push' into GUI layer (EDT)
String text = "Your error here";
publish(text);
Boolean result = Boolean.TRUE;
// continue with remaining process
return result;
}
protected void process(List<Object> chunks) {
String[] message = chunks.toArray(new String[chunks.size()]);
// prompt user with dialog box
JDialogBox.showMessageDialog(window, message);
}
b) внутри сделано (),
protected void done() {
// prompt user with dialog box
String message;
try {
message = get();
} catch (Exception e) {
e.printStackTrace();
}
JDialogBox.showMessageDialog(window, message);
}
в) или снаружи get ()?
SwingWorker sw = new SwingWorker() {.....;
sw.execute();
// some time later
final String message;
try {
message = sw.get();
} catch (Exception e) {
e.printStackTrace();
}
Runnable edt = new Runnable() {
public void run() {
JDialogBox.showMessageDialog(window, message);
}
}
java.awt.EventQueue.invokeLater(edt);