This is not a mistake, you need to start the hard work and do light weight work in the saddle thread next to the main thread. This is necessary due to logical violations between the GUI dialog dialog box and its ActionListenerEvents attitude towards the heavy work of the scales in the background. If you do not share your main thread, you will be able to track the Swing draw due to some event notifications. I had the same problem, I tried to track the progress of the FTP upload that I started with JFrame to show it in JDialog.
First I tried:
//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); // ... } //... }
But this way I bind the JDialog FrameBorder and the balck content panel, but ...
Next attempt:
//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(); // ... } //... }
and finally it worked, hope this helps;)
source share