File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes CountDownLatch and Hanging Windows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "CountDownLatch and Hanging Windows" Watch "CountDownLatch and Hanging Windows" New topic
Author

CountDownLatch and Hanging Windows

Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 217
I was not sure which forum this really belonged in so I am posting here. I have a menu item for printing. However, before calling the print method, I need to get an option from the user. So within the menu action handler I launch the option dialog with a countdown latch:

PrintType is the class that manages the option dialog.

The objective is that when the user clicks the submit button, the selected radio button is saved, the latch decremented and the window closed so it will proceed to the print dialog. Without the latching, the option dialog and the print dialog come up together and the option dialog, although properly displayed, cannot be used while the print dialog is up. I want to reverse that. I want the option dialog to happen first thus the reason for the latch. Unfortunately, while the option dialog comes up with the latch, it is not fully displayed. It has the same background as the underlying window and the buttons and labels are never displayed. At that point the application is hung and the only way to close it is to kill it from the OS. I also tried using invokelater to set up a separate thread but got the same results. Obviously something somewhere is waiting for something to happen that prevents the dialog window from even being completely displayed. Can someone spot what I am doing wrong? TIA.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19792
    
  20

Concurrency in Swing. In other words, long lasting or blocking code should never be performed directly inside event handling methods but you should use a SwingWorker, thread (with EventQueue.invokeLater for notifying the GUI) or SecondaryLoop instead.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 217
Thanks for the reply. That first link is dead. I only glanced at SwingWorker but I take it that is different then the invokelater I used that didn't work. I'll have to read up on the SwingWorker.

After further review, I think SecondaryLoop is more applicable to my situation.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19792
    
  20

I guess my keyboard macro is out of date. Here's the correct link: http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html
Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 217
Thanks again and SecondaryLoop solved the problem.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19792
    
  20

You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CountDownLatch and Hanging Windows