I have banking gui application that I am currently working on and there seems to be a problem with the setvisible method for my jdialog. After the user has withdrawn a valid
setVisible
is a method that affects the GUI, causing something to be shown (and, in the case of a modal dialog like yours, block until the dialog is closed). It (like everything else that modifies the visible UI) should never be called except on the Swing event dispatch thread. You're calling it from the doInBackground
method of SwingWorker
, which runs on a background thread.
What you need to do to fix this is make the waitForClose
dialog a final
variable that you create before calling execute
on the SwingWorker
and then call setVisible
on immediately after starting the worker.
final JDialog waitForTrans = ...
// set up the dialog here
SwingWorker worker = new SwingWorker() {
...
};
worker.execute(); // start the background process
waitForTrans.setVisible(true); // show the dialog
You need to do it in this order because otherwise the modal dialog will block you from starting the worker.