等待 Swing 的元素重绘完成
我希望能够等待 Swing 的 repaint
完成。
示例:
frame.repaint();
wait_for_repaint_to_finish();
//work
我有这样的事情:
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
try {
frame.repaint();
} catch (Exception e) {
e.printStackTrace();
}
}
});
这是正确的方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是为什么你需要这样的东西?为什么要重新绘制整个框架并等待它完成。如果我们知道您正在尝试做什么,我们可能会给出更好的建议。
repaint() 只是安排要完成的绘制。 RepaintManager 可能会合并多个绘制请求并一次执行这些请求,以使绘制更加高效。
话虽如此,如果您确实需要强制重新绘制,您可以使用
但这只能作为最后的手段,而不是解决设计问题。
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
But this should only be used as a last resort and not to fix a design problem.
您可以重写
paintComponent()
:You can override
paintComponent()
: