|
These are the three easy steps:
RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());
SwingUtilities.invokeAndWait()
but make sure you're
not already on the EDT first. This method won't return until the
Runnable you've passed to it is complete. This means you can safely
assume that the Runnable is complete on later lines in the code.
Alternatively, you can use SwingUtilities.invokeLater(). This will let the invoking thread continue to do other things. If the Runnable and the invoking thread are doing unrelated tasks in parallel, this is a good thing. However, if you later try to use the objects being used in the Runnable the access should be synchronized to ensure the EDT and your thread don't conflict.
Copyright © 2024 Andrew Oliver