相关疑难解决方法(0)

如何在非事件派发线程中提示确认对话框

我有以下fun将由非事件派发线程执行.在线程中间,我想要一个

  1. 弹出确认框.线程暂停其执行.
  2. 用户做出选择.
  3. 线程将获得选择并继续执行.

但是,我发现以线程安全方式执行它并不容易,因为对话框应该由事件调度线程显示.我试试

public int fun()
{
    // The following code will be executed by non event dispatching thread.
    final int choice;
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            // Error.
            choice = JOptionPane.showConfirmDialog(SaveToCloudJDialog.this, message, title, JOptionPane.YES_NO_OPTION);
        }            
    });
    return choice;
}
Run Code Online (Sandbox Code Playgroud)

当然这不会choice是最终的,我不能将对话框的返回值分配给它.

实现上述3个目标的正确方法是什么?

java swing multithreading event-dispatch-thread

5
推荐指数
1
解决办法
4797
查看次数

是否有可能有多个JOptionPane对话框?

有谁知道我们如何在另一个JOptionPane对话框上面有一个JOptionPane对话框?

java swing multithreading jcomponent joptionpane

2
推荐指数
1
解决办法
3766
查看次数