0

I'm working on a Tool to read XML-files from a collection and write the information into a text-file. This process can take a few seconds and my program gets the "no response" in the title ...

"no response" in the title

Is there a simple way to inform the user, that the program is still working? like implementing a loading image or a 3-dot animation with a Label?

I have no experience with this topic

This is the current method to read the files and write the txt:

@FXML
public void FullFilterAndExport() throws JAXBException, IOException {
    totalFilesCount = 0;
    totalFilesCountPositive = 0;
    PrintWriter pWriter = new PrintWriter(new BufferedWriter(new FileWriter(DB_Path.toString() + "\\export_full.txt")));        
    for(String file: FileList) {
        if (file.endsWith(".xml") && !file.contains("databaseinfo.xml")) {
            totalFilesCount = totalFilesCount +1;
            ItemList.clear();
            JAXBContext context = JAXBContext.newInstance(NotesDocumentMetaFile.class);
            Unmarshaller um = context.createUnmarshaller();
            NotesDocumentMetaFile docMetaFile = (NotesDocumentMetaFile) um.unmarshal(new FileReader(file));

            for(int i = 0; i < docMetaFile.getItems().size(); i++) {
                if(docMetaFile.getItems().get(i).getValueIsSpecial() == true) {
                    ItemList.add("Itemname:" + docMetaFile.getItems().get(i).getName());
                }
            }
            if(!ItemList.isEmpty()) {
                totalFilesCountPositive = totalFilesCountPositive + 1;
                pWriter.println(file);
                pWriter.println();
                for(String item : ItemList) {
                    pWriter.println(item);
                }
                pWriter.println();
            }

        }
    }
    pWriter.println();
    pWriter.println("------------------");
    pWriter.println("Anzahl der geprüften Dateien: " + totalFilesCount);
    pWriter.println("Anzahl der geprüften positiven Dateien: " + totalFilesCountPositive);
    if (pWriter != null){ 
        pWriter.flush(); 
        pWriter.close();
    }
}
T_Ix
  • 66
  • 8
  • 2
    The way to handle this is universal for all types of UI technologies: do not do lengthy jobs in the UI thread, rather spawn background threads for that purpose. JavaFX supports this with `Task`s and `Service`s in the `javafx.concurrent` package. – Nikos Paraskevopoulos Jul 10 '17 at 11:18
  • thanks... seems like what I'm looking for... could u provide an example with the code above? this method is part of a controller class and triggered by pressing a button.... so far I guess I have to make a additional class which will be the service? – T_Ix Jul 10 '17 at 13:27
  • 1
    https://stackoverflow.com/documentation/javafx/2230/threading/7291/updating-the-ui-using-platform-runlater#t=201707101500450803679 ; `Task` may also be a promising option in case you want to display a message / progress in the UI... – fabian Jul 10 '17 at 15:02

0 Answers0