This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, I encounter the problem in the code that is pasted below and have no idea where the problem lies. The crucial part of the code is MyAction.actionPerformed method. It simply makes the modal-dialog visible (which blocks the thread) but on the previous line it starts the thread that will call the SwingUtilities.invokeLater with the Runnable that hides the dialog. This way the thread that shows the dialog will be blocked till the thread that calls invokeLater does his jobs and hides the dialog. All code runs in Swing-event-thread except the Thread that is created only invoke the SwingUtilities.invokeLater method. The problem is that when you run the app and try to run the MyAction (it is plugged as GO item in the frame's menu) a few times you see that the dialog is not alway correctly hidden (someties I need 20 tries to see the effect). Sometimes the bug manifest itself by not hiding the dialog (and additionaly the dialog is broken - either it does not have anything inside contentPane or it is just window-title-bar without any content below) sometimes the dialog is hidden but the frame does not give the focus back (as if the dialog was still displayed but was invisible). Calling the dispose instead of setVisible(false) has the similar effect. The problem looks like some kind of race, but how it could be if everything is done from the Swing-thread. I observer the problem on sun-jdk-126.96.36.199 and ibm-jdk-188.8.131.52 I would be grateful for any tips on that problem.