这不是错误,您必须在主线程旁边的单独线程中运行您的重量级工作和轻量级摆动工作。这是必要的,因为 Dialog GUI 线程和它的 ActionListenerEvents 关系之间的逻辑冲突与后台的繁重工作有关。如果你不分开你的主线程将由于一些通知事件而确定 Swing 抽奖。我遇到了同样的问题,我尝试监视从 JFrame 开始的 FTP 上传进度的进度,以在 JDialog 中显示它。
首先我试过:
//Activated by Upload Button
public void actionPerformed(ActionEvent e) {
if("Upload".equals(e.getActionCommand())){
// some Declarations
new Thread(){
public void run() {
/*Run JDialog with the Upload - ProgressBar*/
FileUploadProgressBar fileUploadProgressBar = new FileUploadProgressBar(localFile, remoteFile, ftpPersistence);
}
}.start();
/*Run the heavy weigth Job - the Upload*/
ftpPersistence.uploadFile(localFile, remoteFile);
// ...
}
//...
}
但是这样我就获得了一个 JDialog FrameBorder 和一个黑色的内容窗格但是......
下次尝试:
//Activated by Upload Button
public void actionPerformed(ActionEvent e) {
if("Upload".equals(e.getActionCommand())){
// some Declarations
new Thread(){
public void run() {
/*Run JDialog with the Upload - ProgressBar*/
FileUploadProgressBar fileUploadProgressBar = new FileUploadProgressBar(localFile, remoteFile, ftpPersistence);
}
}.start();
new Thread(){
public void run()
/*Run the heavy weigth Job - the Upload*/
ftpPersistence.uploadFile(localFile, remoteFile);
}
}.start();
// ...
}
//...
}
最后它起作用了,希望它会有所帮助;)