Pergunta

We use FileDialog for open/save menus. When we save the file, first we populate the modal window using FileDialog. After user inputs the file name, the saving operation takes a long time ( up to 45 seconds) as there is a time consuming export process involved. So the problem is, during the export process, the FileDialog window is closed but there is a gray area in the FileDialog's location. Until the saving process is completed, the gray area will be cleared. Code is:

 File file = null;
 File fd = new FileDialog(mainFrame, "Save", FileDialog.SAVE);

 fd.setDirectory("./");
 fd.setLocation(50, 50);
 fd.setVisible(true);

 if (fd.getFile() != null) {
   file = new File(fd.getDirectory() + fd.getFile());
 }

 // This is a time consuming process
 ExportFromDB edb = new ExportFromDB(); 
 // Program continues

Is there any way to clear the FileDialog window completely? thanks

Foi útil?

Solução

The gray box you are seeing is because the EDT is blocked and is unable to update the GUI.

You should look into using SwingWorker to perform the long running task on a background thread.

Another option available under Java 7 is SecondaryLoop.

Take a look at Hidden Java 7 Features – SecondaryLoop for a detailed explanation & example.

Outras dicas

Your UI is going to be "Stuck" until your export finishes, the best thing to do would be to do the work in a separate thread.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top