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

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

    Have you tried:

    public int fun()
    {
        // The following code will be executed by non event dispatching thread.
        final int[] choice = new int[1];
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                // Error.
                choice[0] = JOptionPane.showConfirmDialog(SaveToCloudJDialog.this, message, title, JOptionPane.YES_NO_OPTION);
            }            
        });
        return choice[0];
    }
    

提交回复
热议问题