本文介绍了如何在Java中延迟MessageDialogBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以在这段代码中:
//Actions performed when an event occurs.
public void actionPerformed(ActionEvent event)
{
String command = event.getActionCommand();
//If btnConvertDocuments is clicked, the FileConverter method is called and the button is then disabled [so as to prevent duplicates].
if (command.equals("w"))
{
new Thread(new Runnable()
{
public void run()
{
FileConverter fc = new FileConverter();
}
}).start();
btnConvertDocuments.setEnabled(false);
//Validation message ensuring completion of the step.
JOptionPane.showMessageDialog(this, "Step 1 Complete!", "Validation", JOptionPane.INFORMATION_MESSAGE);
}
似乎消息对话框窗口弹出方式太快了, FileConverter方法甚至没有被完成调用。我想知道JOptionPane的位置是否正确,或者是否有办法延迟消息直到方法完成处理?
It seems like the message dialog window pop-ups way too fast, before the FileConverter method isn't even finished being called. I was wondering if the placement of JOptionPane was correct, or if there was a way to delay a message until the method finished processing?
推荐答案
您可以使用。
请看这里,。
SwingWorker worker = new SwingWorker<Void, Void>() {
@Override
public Void doInBackground() {
FileConverter fc = new FileConverter();
return null;
}
@Override
public void done() {
JOptionPane.showMessageDialog(this, "Step 1 Complete!", "Validation", JOptionPane.INFORMATION_MESSAGE);
}
};
这篇关于如何在Java中延迟MessageDialogBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!