Prevent Swing GUI from freezing when calling a method that accesses Swing components and takes a lot of time

Next line:

SwingUtilities.updateComponentTreeUI(aComponent);

makes my GUI immune.

Calling this method takes a lot of time to update laf on most of the GUI, so the GUI does not respond during this operation.

Since this operation controls the GUI, you cannot use SwingWorker for this. From the SwingWorker documentation:

  • Time-consuming tasks should not be run in the event dispatch thread. Otherwise, the application becomes unresponsive.

  • Swing components should be available in the "Event Manager" section only.

The problem here lies in the fact that the operation to access Swing components and takes a long time.

Is there a good way to prevent this irresponsibility?

+3
source share
2 answers

Since you are changing L & F, and this can greatly affect the appearance and usability of the GUI, ask yourself if you really want the application to respond during this time. It might be better to display a message (“Wait ...” or something else) using the glass panel and freeze the GUI while the L & amp F is updated.

, , , .

+2

, , , - . , , , .

updateComponentTree , , "", , ..

, , , / , , , , , , .

0

All Articles