Swing中paint,paintComponent和paintComponents之间的区别 [英] Difference between paint, paintComponent and paintComponents in Swing
本文介绍了Swing中paint,paintComponent和paintComponents之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
paint()
, paintComponent()
和 paintComponents之间的实际差异是什么? Java Swing中的()
?
我试图理解Oracle文档中的解释,但我不清楚。
I tried to understand what explained in Oracle docs but I am not clear.
推荐答案
- AWT,覆盖
paint()
。 - Swing顶级容器(例如
JApplet
,JFrame
,JWindow
,JDialog
..),覆盖paint()
。但是有一些很好的理由不在TLC中绘画。也许是一个单独问题的主题。 - Swing的其余部分,覆盖
paintComponent()
。 - 既不覆盖也不显式调用
paintComponents()
,将其留给API以在需要时调用它。 - AWT, override
paint()
. - Swing top-level container (e.g.s are
JApplet
,JFrame
,JWindow
,JDialog
..), overridepaint()
. But there are a number of good reasons not to paint in a TLC. A subject for a separate question, perhaps. - The rest of Swing, override
paintComponent()
. - Neither override nor explicitly call
paintComponents()
, leave it to the API to call it when needed.
请务必在覆盖方法时使用 @Override
表示法。
Be sure to also use @Override
notation whenever overriding a method.
这样做会暗示试图在 JFrame $ c中覆盖
paintComponent(..)
的问题$ c>(它没有这样的方法),这很常见。
Doing so would hint at the problem of trying to override paintComponent(..)
in a JFrame
(it has no such method), which is quite common to see.
这篇关于Swing中paint,paintComponent和paintComponents之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文