I want to be able to wait for Swing's repaint completion.
Example:
frame.repaint();
wait_for_repaint_to_finish();
//work
I have something like this:
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
try {
frame.repaint();
} catch (Exception e) {
e.printStackTrace();
}
}
});
Is this the correct way to do it?
The question is why do you need something like this? Why would you ever repaint the entire frame and wait for it to be complete. If we know what you are attempting to do we can probably give a better suggestion.
repaint() just schedules painting to be done. The RepaintManager will potentially consolidate multiple paint requests and do them at one time to make paintng more efficient.
Having said that, if you really need to force a repaint you can use
JComponent.paintImmediately(...);
But this should only be used as a last resort and not to fix a design problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With