• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

CountDownLatch and Hanging Windows

 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again and SecondaryLoop solved the problem.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
reply
    Bookmark Topic Watch Topic
  • New Topic