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

后端 未结 6 451
滥情空心
滥情空心 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:32

    public int fun() throws InterruptedException, InvocationTargetException {
        // The following code will be executed by non event dispatching thread.
        ChoiceRunnable runabble = new ChoiceRunnable();
        SwingUtilities.invokeAndWait(runabble);
    
        return runabble.choice;
      }
    
      class ChoiceRunnable implements Runnable {
        private int choice;
    
        public void run() {
          choice = JOptionPane.showConfirmDialog(SaveToCloudJDialog.this, message, title, JOptionPane.YES_NO_OPTION);
        }
      }
    

提交回复
热议问题