Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CountDownLatch and Hanging Windows

 
Dennis Putnam
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dennis Putnam
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again and SecondaryLoop solved the problem.
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic