JFrame.repaint()和JPanel.repaint()之间的区别 [英] difference between JFrame.repaint() and JPanel.repaint()

查看:1033
本文介绍了JFrame.repaint()和JPanel.repaint()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以请任何人解释 JPanel.repaint()方法和 JFrame.repaint()方法之间的区别,我想两者都在JPanel中调用 paintComponent()方法。

can please anyone explain the difference between JPanel.repaint() method and JFrame.repaint() method, i guess both calls the paintComponent() method in JPanel.

请澄清,谢谢

推荐答案

致电 repaint()在任何Component上都会向重绘管理器添加一个请求以绘制该组件。如果条件正确,管理员将安排调用Component的 paint(...)方法。由于Component的paint方法将调用 paintComponent(...) paintBorder(...) paintChildren(...)这将使组件绘制本身,它的边框和级联绘画以递归方式呈现给它的所有子节点,子节点,子节点等等。在JFrame上调用它将导致此级联在整个顶级窗口中发生,而在子组件上调用它将导致仅重新绘制该组件及其子组件。

Calling repaint() on any Component will add a request to the repaint manager to paint that component. If conditions are correct, the manager will then arrange to have the Component's paint(...) method called. Since a Component's paint method will then call paintComponent(...), paintBorder(...) and paintChildren(...) this will have the component paint itself, its border and cascade painting recursively to all of its children, their children, their children's children, etc. Calling this on JFrame will cause this cascade to occur throughout the entire top-level window whereas calling it on a subcomponent will cause a repainting of that component and its children only.

请注意调用 repaint()不保证重绘管理器将绘制组件,尤其是在存在堆叠请求的情况下。有关详细信息,请参阅在AWT和Swing中绘画

Note that calling repaint() does not guarantee that the repaint manager will paint the component, especially if there are stacked requests. For more on the details, please read Painting in AWT and Swing.

这篇关于JFrame.repaint()和JPanel.repaint()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆