I couldn't find a better way to express the problem in the title of the question, but hopefully you'll understand...
I have the following code...
[...]
final JDialog waitingDialog = optionPane.createDialog(optionPane, "Processing in backgroung");
waitingDialog.setLocationRelativeTo(homeFrame);
waitingDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
SwingWorker<Void, Void> backgroundThread = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
// Background processing is done here
System.out.println("[DEBUG] -- Background processing has started");
MyCustomClass.initParameters();
System.out.println("DEBUG] -- initParameters() has finished. Starting main processing now...");
waitingDialog.setVisible(true);
MyCustomClass.run();
return null;
}
// This is called when background thread above has completed
@Override
protected void done() {
waitingDialog.dispose();
};
};
backgroundThread.execute();
[and does other things after this...]
... which executes just fine until it hits MyCustomClass.run()
. When it is supposed to start such method, it simply doesn't do it. The application doesn't pause, stop or crash... it just keeps on waiting to continue after the background processing is done, which is not happening for some unknown reason.
MyCustomClass.run()
is a static
method over at MyCustomClass
. I suspected the problem could be with its name - run - so I changed it to some random thing like "doIt()", but the issue persisted.
The very first line on the method is a simple System.out.println("I got here")
, but not even that gets printed.
I added breakpoints just before and right after the method invocation and tried debugging, but that didn't help either. Everything seemed fine and I couldn't find out the problem.
Edit
I ask: how do I make the dialog show only when I wanted it to show? In other words, the script is:
- show the "waiting" dialog when SwingWorker is started
- hide/stop/disable/dispose the dialog when the initParameter() issues the option dialog that needs user input (press of a button);
- show the waiting dialog again as the processing resumed
- dispose of the dialog because the background processing has completed