Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
在完成所有初始化之前不要显示对话框,即将 setVisible 移至构造函数中的最后一个方法。
为了更好地重用,根本不要让 JFrame 派生类调用 setVisible(true),让客户端来执行。
问题是,一旦显示窗口,对窗口所做的任何更改都必须在 GUI 线程上完成,否则您将遇到像您所看到的那样的虚假问题。
Don't show the dialog until all the initialization is done, ie move the setVisible to the last method in the constructor.
for better reuse, don't have the JFrame derived class call setVisible(true) at all, let the client do it.
The problem is, once you show the window, any changes you make to the window MUST be done on the GUI thread, or else you will get spurious problems like you are seeing.
您通常在
paintComponent
中做的第一件事是通过super.paintComponent()
清除屏幕外位图 - 我敢打赌这就是您的问题。The first thing you normally do in
paintComponent
is clear the off-screen bitmap viasuper.paintComponent()
- I bet thats your problem.