actually i have called the swing worker from a frame (Suppose) A.. in the swing worker class in do-in-Background method i have certain db queries and i am calling frame B too..
The done()
method of the SwingWorker
is usually overridden to display the final result. Upon
completion of doInBackground()
, the SwingWorker
automaticlly invokes
done()
in the EDT. So put your frame's invisible and visible code in this function.
The doInBackground()
is not meant to do any GUI rendering task. You can invoke publish(V)
from doInBackground()
function which in turn invokes The process(V)
method to run inside the EDT and performing GUI rendering task.
So a sample solution would be:
class Worker extends SwingWorker<Void, String> {
JFrame frameA;
public Worker(JFrame frameA) {
this.frameA = frameA;
}
@Override
protected void done() {
frameA.dispose();
new frameB().setVisible(true);
}
//other code
}
Now, create you SwingWorker
instance by passing the target frame to it's constructor: new Worker(frame)
; For your context you probably could make use of this
However, you should not really design your application to be dependent on multiple JFrame
. There are reasons for not to use multiple JFrame
window. For more, see The Use of Multiple JFrames, Good/Bad Practice?. A general work around with use case where multiple frame would be needed is explained here.