0

the loading function of my program is running in the main thread. I can't draw any changes on the JFrame during the process. If I use a SwingWorker, the loading process gets chronologically messed up and the construction of the Swing elements is buggy.

A hanging GUI during loading would be undramatic. The only thing is that I would like to include a loading animation. I have already created this, it runs in a new thread.

What are the possibilities to pause the loading process from the thread to draw the changes on the JFrame?

I will gladly embed code. However, the loading process runs through the entire program. So just ask for useful snippets.

hinrich.
  • 13
  • 3
  • 1
    "running in the main thread" should not block the GUI, probably running on the EDT (Event Dispatch Thread). Usually such long lasting operations should run on a different thread, like using `SwingWorker`, which works pretty well. Given information is not sufficient to know why it is not working for you – user16320675 Mar 29 '22 at 08:41
  • See [Concurrency in Swing](https://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html) and [Worker Threads and SwingWorker](https://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html) – MadProgrammer Mar 29 '22 at 08:55
  • For [example](https://stackoverflow.com/questions/24835638/issues-with-swingworker-and-jprogressbar/24835935#24835935); [example](https://stackoverflow.com/questions/14802662/splash-screen-progress-bar-not-drawing/14803941#14803941); [example](https://stackoverflow.com/questions/69275599/jframe-splash-screen-wont-display-an-image/69276856#69276856); [example](https://stackoverflow.com/questions/14928586/how-to-show-a-splash-screen-load-datas-in-the-background-and-hide-the-splash-s/14928981#14928981) – MadProgrammer Mar 29 '22 at 08:59
  • Thanks to all of you — you've helped me a lot. Parts of the loading routine were missing inside the SwingWorker. Now it works fine. – hinrich. Mar 29 '22 at 09:45

0 Answers0