.setVisible(true) immediate repaint

给你一囗甜甜゛ 提交于 2019-12-01 17:45:26

I realise that this answer is being suggested a year after the question was asked, but I had a similar problem and of course researched a bit before I tried to solve it. For anyone who comes across this question, try disposing your window / frame before you pack and make it visible.

This is because each AWT window has an off-screen image that is kept in sync with the on-screen image. When a window is displayed, its contents are painted directly from the off-screen image. This happens on the toolkit thread, not on the event dispatch thread.

Only after the window is shown, the frame is repainted on the event dispatch thread.

Before Java 1.6, there was no per-window double buffering in the AWT, so you would have seen a gray background which was the infamous "gray rectangle" problem.

The only workaround I'm aware of is to create a new frame each time. You can reuse the content panel of the old frame, so the overhead is not so high.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!