How to prompt a confirmation dialog box in the middle of non event dispatching thread

后端 未结 6 601
滥情空心
滥情空心 2021-01-19 00:09

I have the following fun which will be executed by non event dispatching thread. In the middle of thread, I want a

  1. A confirmation box pop up. Thre
6条回答
  •  耶瑟儿~
    2021-01-19 00:11

    Contrary on the popular belief you dont need to dispatch to AWT (EventQueue) thread to show the dialog. So just show it.

    When you do JOptionPane,showMessge() your thread (Thread.currentThread()) is going to do wait(), and the dialog will pop up. Use the result after showMessage and you're good to go.

    Thus:
    choice = JOptionPane.showConfirmDialog(this, message, title, JOptionPane.YES_NO_OPTION);

提交回复
热议问题