I'm doing a program that creates some Excel files (.xlsx) in an specific folder and I've got a problem with GUI because it's freeze when I call to the method that creates this files.
I want that in the GUI there was a progress bar indeterminate that doesn't stot except there was an exception and a JLabel to show the excel file that it's in creation.
MailPanel class: it's the interface, when I click in a button called "Generate" calls to the method "generateExcel" of the class GenerateExcel()
public class MainPanel extends JPanel {
.....
.....
btnGenerate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jsonFileIssues = ..... ;
jsonFileProject = ..... ;
Project project = ..... ;
key = project.getKey();
category = project.getCategory();
String ruta = "C:\\JIRA\\JIRA-Proyectos\\" + category + "\\";
.....
GenerateExcelExterno gee = new GenerateExcelExterno(jsonFileProject, jsonFileIssues, key, ruta, excelFile);
gee.execute();
.....
}
}
.....
.....
}
GenerateExcel class: where it's the importante method to generate the files
I know that I've to add SwingWorker to the GenerateExcel class to unfreeze the GUI, but I can't get it!
The method CREATES the documents, so the doInBackground works, but the progress bar in the panel continues freezed...
public class GenerateExcel extends SwingWorker<Integer, Void> {
String jsonFileProject, jsonFileIssues, key, ruta, excelFile;
public GenerateExcel(String jsonFileProject, String jsonFileIssues,
String key, String ruta, String excelFile) {
super();
this.jsonFileProject = jsonFileProject;
this.jsonFileIssues = jsonFileIssues;
this.key = key;
this.ruta = ruta;
this.excelFile = excelFile;
}
public static void generateExcel(String jsonFileProject, String jsonFileIssues, String key, String ruta, String excelFile) {
.....
.....
.....
}
@Override
protected Integer doInBackground() throws Exception {
// TODO Auto-generated method stub
generateExcelExterno(jsonFileProject, jsonFileIssues, key, ruta, excelFile);
return 100; //for example
}
}