为什么paintComponent执行了2次?
我有以下代码:
canvas=new MembershipFunctionComponent(functions);
canvas.setPreferredSize(new Dimension((int)this.getWidth(), (int)this.getHeight()));
canvas.addMouseListener(canvas);
pane.add(canvas);
MembsershipFunctionComponent 扩展 JComponent。为什么paintComponent方法执行了2次?
I have following code:
canvas=new MembershipFunctionComponent(functions);
canvas.setPreferredSize(new Dimension((int)this.getWidth(), (int)this.getHeight()));
canvas.addMouseListener(canvas);
pane.add(canvas);
MembsershipFunctionComponent extends JComponent. Why is paintComponent method executed 2 times?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
paintComponent
几乎可以随时被 Swing 框架调用。这种情况可能发生的示例:这些都不应该让您担心 - 您应该只编写代码,这样它就不会关心调用 PaintComponent 了多少次。
paintComponent
can get called at pretty much any time by the Swing framework. Examples of when this might happen:None of this should worry you - you should just write your code so that it doesn't care how many times paintComponent is called.