fischvogel
fischvogel

Reputation: 21

Close a java modal JDialog from within the owner class (a JFrame)

i am feeling a bit bad about this question because i think this is probably not the way a JDialog should be used but anyway:

I have a very simple JDialog that just contains a label and i want to show it in situations where the application is running a task that just runs for a few seconds on the main swing thread. The dialog has to be model to make sure that the user cannot click anything on the main GUI while the short blocking task is executed. When the task is done, the modal dialog should be disposed of without any user interaction... and this does not seem to work with a modal dialog since once it's setVisible(true) method is called, execution seems to stop and i can't figure out how to close it from the owner side without user interaction...

I would be very grateful for help or suggestions on how to implement such a blocking dialog in a different way.

Upvotes: 2

Views: 1046

Answers (1)

ControlAltDel
ControlAltDel

Reputation: 35011

Yes, your execution will stop if you show a modal dialog on the UI thread. To overcome this, you can use a SwingWorker or even just create a new Thread

Upvotes: 2

Related Questions