0

I have a small dialog with a progress bar. The dialog is opened from a separate thread and gets, as the parent, the main window. The problem is, when I click on the main window, it comes to the front, but not the child dialog.

The child dialog can not be modal, otherwise the thread wouldn't continue. So how can I properly parent the windows, so that, when I click on the main window, the dialog is shown. Maybe the dialog should be opened from the main window? But then the main window would be blocked.

What I would have is, to block the main window operation until the thread is finished, the main window should still be responsive, so I can stop the thread, and the thread (or somebody) should update the progress dialog while running.

Any advice how to set this up?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Devolus
  • 21,661
  • 13
  • 66
  • 113
  • 1
    *"The child dialog can not be modal, otherwise the thread wouldn't continue."* Of course it would, so long as 'the thread' was not the EDT. Is this Swing? – Andrew Thompson Jun 06 '13 at 08:57
  • 1
    @AndrewThompson - what's EDT? – David Jun 06 '13 at 09:02
  • 1
    @david99world EDT = Event Dispatcher Thread – Fildor Jun 06 '13 at 09:12
  • I just tried to set it to modal, but as expected the thread got stuck. :) How do I know who the EDT is? The one who contruscts the dialog? – Devolus Jun 06 '13 at 09:13
  • See also [*Initial Threads*](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html). – trashgod Jun 06 '13 at 09:20
  • _The dialog is opened from a separate thread_ Very bad idea. All Swing code must be called from the EDT. _The problem is, when I click on the main window, it comes to the front, but not the child dialog._ Most likely you failed providing the parent window to the child dialog (use `new JDialog(parentFrame)`)--> this will bring the dialog above the main window when clicking the main window. – Guillaume Polet Jun 06 '13 at 09:40
  • 1
    Possible [example](http://stackoverflow.com/questions/14928213/using-swingworker-to-add-a-progress-bar-in-a-gui/14928329#14928329), [example](http://stackoverflow.com/questions/12020949/jprogressbar-isnt-progressing/12021971#12021971), [example](http://stackoverflow.com/questions/14201102/progress-bar-not-working/14206402#14206402), [example](http://stackoverflow.com/questions/15199091/progress-bar-java/15199220#15199220) – MadProgrammer Jun 06 '13 at 09:57
  • 1
    And from the sound a of it, you might benefit from a read through [Concurrency in Swing](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/) – MadProgrammer Jun 06 '13 at 09:58
  • Thanks, that looks very promising! :) – Devolus Jun 06 '13 at 11:20
  • @MadProgrammer So finally I found a solution here that works, and your comments got me thinking on hwo to properly do this! A very annoying inconvenience solved. :) http://stackoverflow.com/questions/1925656/swing-worker-modal-dialog-wont-close – Devolus Jun 14 '13 at 11:41

0 Answers0