I am nearly finished with one of the projects my boyfriend requested from me. This particular project involves updating the metadata of our pictures to their original state and organizing them into year/month folders. Once it’s completed, I’ll provide more details on its project page.
In the meantime, I wanted to share a very helpful piece of code that took me some time to get right. The problem I faced was that I needed the UI to display logs of the picture processing in real-time, allowing us to spot any anomalies or freezes without relying on the IDE. Though I had tested the code with 1 GB of pictures, our collection is actually around 50 GB, so I wanted to ensure we could monitor the process effectively.
I sought assistance from ChatGPT since my previous attempts had not yielded fruitful results. I posed a simple prompt, asking how I could synchronize and update the logs live on the UI panel. After a few unsuccessful attempts from ChatGPT, I discovered a clear solution: leveraging the SwingWorker class to run in the background while the application is active.
It was a beautifully simple solution, and I had trouble articulating what I needed, leading to unhelpful online answers. Despite ChatGPT’s occasional inaccuracies, it’s becoming easier for me to understand what I want, and it aids my research by broadening my programming vocabulary. By using ChatGPT, I manage to identify the direction I should pursue and then continue my search on the web as well. It took a few days, but I finally obtained the necessary code snippet:
SwingWorker<Void, String> worker = new SwingWorker<Void, String>() {
@Override
protected Void doInBackground() throws Exception {
for (String input : inputStrings) {
logAppend("Counting: " + input);
// Simulate some processing time with a 1-second delay. Just so we can see it in action. Else it all happens in one second.
Thread.sleep(1000);
}
Here is the screengrab example:

Leave a Reply